QGIS API Documentation  2.14.11-Essen
qgsabstractgeometryv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsabstractgeometryv2.h
3  -------------------------------------------------------------------
4 Date : 04 Sept 2014
5 Copyright : (C) 2014 by Marco Hugentobler
6 email : marco.hugentobler at sourcepole dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSABSTRACTGEOMETRYV2
17 #define QGSABSTRACTGEOMETRYV2
18 
19 #include "qgscoordinatetransform.h"
20 #include "qgsrectangle.h"
21 #include "qgswkbtypes.h"
22 #include "qgswkbptr.h"
23 
24 #include <QString>
25 
27 class QgsMapToPixel;
28 class QgsCurveV2;
29 class QgsMultiCurveV2;
30 class QgsMultiPointV2;
31 class QgsPointV2;
32 struct QgsVertexId;
33 class QPainter;
34 
38 
44 class CORE_EXPORT QgsAbstractGeometryV2
45 {
46  public:
48  virtual ~QgsAbstractGeometryV2();
50  virtual QgsAbstractGeometryV2& operator=( const QgsAbstractGeometryV2& geom );
51 
54  virtual QgsAbstractGeometryV2* clone() const = 0;
55 
58  virtual void clear() = 0;
59 
62  virtual QgsRectangle boundingBox() const = 0;
63 
64  //mm-sql interface
68  virtual int dimension() const = 0;
69  //virtual int coordDim() const { return mCoordDimension; }
70 
75  virtual QString geometryType() const = 0;
76 
81  QgsWKBTypes::Type wkbType() const { return mWkbType; }
82 
87  QString wktTypeStr() const;
88 
92  bool is3D() const;
93 
97  bool isMeasure() const;
98 
99 #if 0
100  virtual bool transform( const QgsCoordinateTransform& ct ) = 0;
101  virtual bool isEmpty() const = 0;
102  virtual bool isSimple() const = 0;
103  virtual bool isValid() const = 0;
104  virtual QgsMultiPointV2* locateAlong() const = 0;
105  virtual QgsMultiCurveV2* locateBetween() const = 0;
106  virtual QgsCurveV2* boundary() const = 0;
107  virtual QgsRectangle envelope() const = 0;
108 #endif
109 
110  //import
111 
115  virtual bool fromWkb( QgsConstWkbPtr wkb ) = 0;
116 
120  virtual bool fromWkt( const QString& wkt ) = 0;
121 
122  //export
123 
127  virtual int wkbSize() const = 0;
128 
137  virtual unsigned char* asWkb( int& binarySize ) const = 0;
138 
146  virtual QString asWkt( int precision = 17 ) const = 0;
147 
157  virtual QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
158 
168  virtual QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
169 
177  virtual QString asJSON( int precision = 17 ) const = 0;
178 
179  //render pipeline
180 
186 
190  virtual void transform( const QTransform& t ) = 0;
191 
192 #if 0
193  virtual void clip( const QgsRectangle& rect ); //todo
194 #endif
195 
199  virtual void draw( QPainter& p ) const = 0;
200 
207  virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const = 0;
208 
212  virtual QgsCoordinateSequenceV2 coordinateSequence() const = 0;
213 
216  virtual int nCoordinates() const;
217 
220  virtual QgsPointV2 vertexAt( QgsVertexId id ) const = 0;
221 
231  virtual double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const = 0;
232 
233  //low-level editing
234 
242  virtual bool insertVertex( QgsVertexId position, const QgsPointV2& vertex ) = 0;
243 
251  virtual bool moveVertex( QgsVertexId position, const QgsPointV2& newPos ) = 0;
252 
259  virtual bool deleteVertex( QgsVertexId position ) = 0;
260 
265  virtual double length() const { return 0.0; }
266 
271  virtual double perimeter() const { return 0.0; }
272 
277  virtual double area() const { return 0.0; }
278 
280  virtual QgsPointV2 centroid() const;
281 
284  bool isEmpty() const;
285 
288  virtual bool hasCurvedSegments() const { return false; }
289 
293  virtual QgsAbstractGeometryV2* segmentize() const { return clone(); }
294 
299  virtual QgsAbstractGeometryV2* toCurveType() const { return 0; }
300 
307  virtual double vertexAngle( QgsVertexId vertex ) const = 0;
308 
309  virtual int vertexCount( int part = 0, int ring = 0 ) const = 0;
310  virtual int ringCount( int part = 0 ) const = 0;
311 
316  virtual int partCount() const = 0;
317 
325  virtual bool addZValue( double zValue = 0 ) = 0;
326 
334  virtual bool addMValue( double mValue = 0 ) = 0;
335 
342  virtual bool dropZValue() = 0;
343 
350  virtual bool dropMValue() = 0;
351 
356  virtual bool convertTo( QgsWKBTypes::Type type );
357 
358  protected:
360 
363  void setZMTypeFromSubGeometry( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );
364 
368  virtual QgsRectangle calculateBoundingBox() const;
369 
372  virtual void clearCache() const {}
373 
374 };
375 
376 
382 struct CORE_EXPORT QgsVertexId
383 {
385  {
386  SegmentVertex = 1, //start / endpoint of a segment
387  CurveVertex
388  };
389 
390  QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
391  : part( _part ), ring( _ring ), vertex( _vertex ), type( _type ) {}
392 
395  bool isValid() const { return part >= 0 && ring >= 0 && vertex >= 0; }
396 
397  bool operator==( QgsVertexId other ) const
398  {
399  return part == other.part && ring == other.ring && vertex == other.vertex;
400  }
401  bool operator!=( QgsVertexId other ) const
402  {
403  return part != other.part || ring != other.ring || vertex != other.vertex;
404  }
405  bool partEqual( QgsVertexId o ) const
406  {
407  return part >= 0 && o.part == part;
408  }
409  bool ringEqual( QgsVertexId o ) const
410  {
411  return partEqual( o ) && ( ring >= 0 && o.ring == ring );
412  }
413  bool vertexEqual( QgsVertexId o ) const
414  {
415  return ringEqual( o ) && ( vertex >= 0 && o.ring == ring );
416  }
417  bool isValid( const QgsAbstractGeometryV2* geom ) const
418  {
419  return ( part >= 0 && part < geom->partCount() ) &&
420  ( ring < geom->ringCount( part ) ) &&
421  ( vertex < 0 || vertex < geom->vertexCount( part, ring ) );
422  }
423 
424  int part;
425  int ring;
426  int vertex;
428 };
429 
430 #endif //QGSABSTRACTGEOMETRYV2
QList< QgsPointV2 > QgsPointSequenceV2
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QgsVertexId(int _part=-1, int _ring=-1, int _vertex=-1, VertexType _type=SegmentVertex)
bool isValid() const
Returns true if the vertex id is valid.
Multi curve geometry collection.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
Abstract base class for all geometries.
Multi point geometry collection.
double closestSegment(const QgsPolyline &pl, const QgsPoint &pt, int &vertexAfter, double epsilon)
Definition: qgstracer.cpp:62
virtual void clearCache() const
Clears any cached parameters associated with the geometry, eg bounding boxes.
bool vertexEqual(QgsVertexId o) const
virtual QgsAbstractGeometryV2 * toCurveType() const
Returns the geometry converted to the more generic curve type.
bool operator!=(QgsVertexId other) const
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
Utility class for identifying a unique vertex within a geometry.
static QgsRectangle calculateBoundingBox(QGis::WkbType wkbType, QgsConstWkbPtr wkbPtr, int numPoints)
Returns the BBOX of the specified WKB-point stream.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
QList< QgsRingSequenceV2 > QgsCoordinateSequenceV2
bool isValid(const QgsAbstractGeometryV2 *geom) const
QList< QgsPointSequenceV2 > QgsRingSequenceV2
virtual double perimeter() const
Returns the perimeter of the geometry.
bool operator==(QgsVertexId other) const
bool partEqual(QgsVertexId o) const
bool ringEqual(QgsVertexId o) const
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
virtual int ringCount(int part=0) const =0
virtual double length() const
Returns the length of the geometry.
Class for doing transforms between two map coordinate systems.
virtual QgsAbstractGeometryV2 * segmentize() const
Returns a version of the geometry without curves.
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether &#39;thepoint&#39; is left or right of the line from &#39;p1&#39; to &#39;p2&#39;.
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
virtual double area() const
Returns the area of the geometry.