QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
26 class QgsMapToPixel;
27 class QgsCurveV2;
28 class QgsMultiCurveV2;
29 class QgsMultiPointV2;
30 class QgsPointV2;
31 struct QgsVertexId;
32 class QPainter;
33 
37 
43 class CORE_EXPORT QgsAbstractGeometryV2
44 {
45  public:
46 
49  {
50  MaximumAngle = 0,
51  MaximumDifference
52  };
53 
55  virtual ~QgsAbstractGeometryV2();
57  virtual QgsAbstractGeometryV2& operator=( const QgsAbstractGeometryV2& geom );
58 
61  virtual QgsAbstractGeometryV2* clone() const = 0;
62 
65  virtual void clear() = 0;
66 
69  virtual QgsRectangle boundingBox() const = 0;
70 
71  //mm-sql interface
75  virtual int dimension() const = 0;
76  //virtual int coordDim() const { return mCoordDimension; }
77 
82  virtual QString geometryType() const = 0;
83 
88  QgsWKBTypes::Type wkbType() const { return mWkbType; }
89 
94  QString wktTypeStr() const;
95 
99  bool is3D() const;
100 
104  bool isMeasure() const;
105 
106 #if 0
107  virtual bool transform( const QgsCoordinateTransform& ct ) = 0;
108  virtual bool isEmpty() const = 0;
109  virtual bool isSimple() const = 0;
110  virtual bool isValid() const = 0;
111  virtual QgsMultiPointV2* locateAlong() const = 0;
112  virtual QgsMultiCurveV2* locateBetween() const = 0;
113  virtual QgsRectangle envelope() const = 0;
114 #endif
115 
121  virtual QgsAbstractGeometryV2* boundary() const = 0;
122 
123  //import
124 
128  virtual bool fromWkb( QgsConstWkbPtr wkb ) = 0;
129 
133  virtual bool fromWkt( const QString& wkt ) = 0;
134 
135  //export
136 
140  virtual int wkbSize() const = 0;
141 
150  virtual unsigned char* asWkb( int& binarySize ) const = 0;
151 
159  virtual QString asWkt( int precision = 17 ) const = 0;
160 
170  virtual QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
171 
181  virtual QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
182 
190  virtual QString asJSON( int precision = 17 ) const = 0;
191 
192  //render pipeline
193 
204  bool transformZ = false ) = 0;
205 
209  virtual void transform( const QTransform& t ) = 0;
210 
211 #if 0
212  virtual void clip( const QgsRectangle& rect ); //todo
213 #endif
214 
218  virtual void draw( QPainter& p ) const = 0;
219 
226  virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const = 0;
227 
231  virtual QgsCoordinateSequenceV2 coordinateSequence() const = 0;
232 
235  virtual int nCoordinates() const;
236 
239  virtual QgsPointV2 vertexAt( QgsVertexId id ) const = 0;
240 
250  virtual double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const = 0;
251 
252  //low-level editing
253 
261  virtual bool insertVertex( QgsVertexId position, const QgsPointV2& vertex ) = 0;
262 
270  virtual bool moveVertex( QgsVertexId position, const QgsPointV2& newPos ) = 0;
271 
278  virtual bool deleteVertex( QgsVertexId position ) = 0;
279 
284  virtual double length() const { return 0.0; }
285 
290  virtual double perimeter() const { return 0.0; }
291 
296  virtual double area() const { return 0.0; }
297 
299  virtual QgsPointV2 centroid() const;
300 
303  bool isEmpty() const;
304 
307  virtual bool hasCurvedSegments() const { return false; }
308 
314  virtual QgsAbstractGeometryV2* segmentize( double tolerance = M_PI / 180., SegmentationToleranceType toleranceType = MaximumAngle ) const;
315 
320  virtual QgsAbstractGeometryV2* toCurveType() const { return 0; }
321 
328  virtual double vertexAngle( QgsVertexId vertex ) const = 0;
329 
330  virtual int vertexCount( int part = 0, int ring = 0 ) const = 0;
331  virtual int ringCount( int part = 0 ) const = 0;
332 
337  virtual int partCount() const = 0;
338 
346  virtual bool addZValue( double zValue = 0 ) = 0;
347 
355  virtual bool addMValue( double mValue = 0 ) = 0;
356 
363  virtual bool dropZValue() = 0;
364 
371  virtual bool dropMValue() = 0;
372 
377  virtual bool convertTo( QgsWKBTypes::Type type );
378 
379  protected:
381 
384  void setZMTypeFromSubGeometry( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );
385 
389  virtual QgsRectangle calculateBoundingBox() const;
390 
393  virtual void clearCache() const {}
394 
395 };
396 
397 
403 struct CORE_EXPORT QgsVertexId
404 {
406  {
407  SegmentVertex = 1, //start / endpoint of a segment
408  CurveVertex
409  };
410 
411  QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
412  : part( _part )
413  , ring( _ring )
414  , vertex( _vertex )
415  , type( _type )
416  {}
417 
420  bool isValid() const { return part >= 0 && ring >= 0 && vertex >= 0; }
421 
422  bool operator==( QgsVertexId other ) const
423  {
424  return part == other.part && ring == other.ring && vertex == other.vertex;
425  }
426  bool operator!=( QgsVertexId other ) const
427  {
428  return part != other.part || ring != other.ring || vertex != other.vertex;
429  }
430  bool partEqual( QgsVertexId o ) const
431  {
432  return part >= 0 && o.part == part;
433  }
434  bool ringEqual( QgsVertexId o ) const
435  {
436  return partEqual( o ) && ( ring >= 0 && o.ring == ring );
437  }
438  bool vertexEqual( QgsVertexId o ) const
439  {
440  return ringEqual( o ) && ( vertex >= 0 && o.ring == ring );
441  }
442  bool isValid( const QgsAbstractGeometryV2* geom ) const
443  {
444  return ( part >= 0 && part < geom->partCount() ) &&
445  ( ring < geom->ringCount( part ) ) &&
446  ( vertex < 0 || vertex < geom->vertexCount( part, ring ) );
447  }
448 
449  int part;
450  int ring;
451  int vertex;
453 };
454 
455 #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.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
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
#define M_PI
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.
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.