QGIS API Documentation  2.12.0-Lyon
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 <QString>
23 
25 class QgsMapToPixel;
26 class QgsCurveV2;
27 class QgsMultiCurveV2;
28 class QgsMultiPointV2;
29 class QgsPointV2;
30 class QgsConstWkbPtr;
31 struct QgsVertexId;
32 class QgsWkbPtr;
33 class QPainter;
34 
35 
41 class CORE_EXPORT QgsAbstractGeometryV2
42 {
43  public:
45  virtual ~QgsAbstractGeometryV2();
47  virtual QgsAbstractGeometryV2& operator=( const QgsAbstractGeometryV2& geom );
48 
51  virtual QgsAbstractGeometryV2* clone() const = 0;
52 
55  virtual void clear() = 0;
56 
59  QgsRectangle boundingBox() const;
60 
64  virtual QgsRectangle calculateBoundingBox() const;
65 
66  //mm-sql interface
70  virtual int dimension() const = 0;
71  //virtual int coordDim() const { return mCoordDimension; }
72 
77  virtual QString geometryType() const = 0;
78 
83  QgsWKBTypes::Type wkbType() const { return mWkbType; }
84 
89  QString wktTypeStr() const;
90 
94  bool is3D() const;
95 
99  bool isMeasure() const;
100 
101 #if 0
102  virtual bool transform( const QgsCoordinateTransform& ct ) = 0;
103  virtual bool isEmpty() const = 0;
104  virtual bool isSimple() const = 0;
105  virtual bool isValid() const = 0;
106  virtual QgsMultiPointV2* locateAlong() const = 0;
107  virtual QgsMultiCurveV2* locateBetween() const = 0;
108  virtual QgsCurveV2* boundary() const = 0;
109  virtual QgsRectangle envelope() const = 0;
110 #endif
111 
112  //import
113 
117  virtual bool fromWkb( const unsigned char * wkb ) = 0;
118 
122  virtual bool fromWkt( const QString& wkt ) = 0;
123 
124  //export
125 
129  virtual int wkbSize() const = 0;
130 
139  virtual unsigned char* asWkb( int& binarySize ) const = 0;
140 
148  virtual QString asWkt( int precision = 17 ) const = 0;
149 
159  virtual QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
160 
170  virtual QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
171 
179  virtual QString asJSON( int precision = 17 ) const = 0;
180 
181  //render pipeline
182 
188 
192  virtual void transform( const QTransform& t ) = 0;
193 
194 #if 0
195  virtual void clip( const QgsRectangle& rect ); //todo
196 #endif
197 
201  virtual void draw( QPainter& p ) const = 0;
202 
209  virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const = 0;
210 
214  virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord ) const = 0;
215 
218  int nCoordinates() const;
219 
222  virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const = 0;
223 
232  virtual double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const = 0;
233 
234  //low-level editing
235 
243  virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex ) = 0;
244 
252  virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos ) = 0;
253 
260  virtual bool deleteVertex( const QgsVertexId& position ) = 0;
261 
266  virtual double length() const { return 0.0; }
267 
272  virtual double perimeter() const { return 0.0; }
273 
278  virtual double area() const { return 0.0; }
279 
281  virtual QgsPointV2 centroid() const;
282 
285  bool isEmpty() const;
286 
289  virtual bool hasCurvedSegments() const { return false; }
290 
294  virtual QgsAbstractGeometryV2* segmentize() const { return clone(); }
295 
299  virtual double vertexAngle( const QgsVertexId& vertex ) const = 0;
300 
301  virtual int vertexCount( int part = 0, int ring = 0 ) const = 0;
302  virtual int ringCount( int part = 0 ) const = 0;
303  virtual int partCount() const = 0;
304 
311  virtual bool addZValue( double zValue = 0 ) = 0;
312 
319  virtual bool addMValue( double mValue = 0 ) = 0;
320 
321  protected:
324 
327  void setZMTypeFromSubGeometry( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );
328 
336  static bool readWkbHeader( QgsConstWkbPtr& wkbPtr, QgsWKBTypes::Type& wkbType, bool& endianSwap, QgsWKBTypes::Type expectedType );
337 
338 };
339 
340 
346 struct CORE_EXPORT QgsVertexId
347 {
349  {
350  SegmentVertex = 1, //start / endpoint of a segment
351  CurveVertex
352  };
353 
354  QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
355  : part( _part ), ring( _ring ), vertex( _vertex ), type( _type ) {}
356 
359  bool isValid() const { return part >= 0 && ring >= 0 && vertex >= 0; }
360 
361  bool operator==( const QgsVertexId& other ) const
362  {
363  return part == other.part && ring == other.ring && vertex == other.vertex;
364  }
365  bool operator!=( const QgsVertexId& other ) const
366  {
367  return part != other.part || ring != other.ring || vertex != other.vertex;
368  }
369  bool partEqual( const QgsVertexId& o ) const
370  {
371  return part >= 0 && o.part == part;
372  }
373  bool ringEqual( const QgsVertexId& o ) const
374  {
375  return partEqual( o ) && ( ring >= 0 && o.ring == ring );
376  }
377  bool vertexEqual( const QgsVertexId& o ) const
378  {
379  return ringEqual( o ) && ( vertex >= 0 && o.ring == ring );
380  }
381  bool isValid( const QgsAbstractGeometryV2* geom ) const
382  {
383  return ( part >= 0 && part < geom->partCount() ) &&
384  ( ring < geom->ringCount( part ) ) &&
385  ( vertex < 0 || vertex < geom->vertexCount( part, ring ) );
386  }
387 
388  int part;
389  int ring;
390  int vertex;
392 };
393 
394 #endif //QGSABSTRACTGEOMETRYV2
bool operator==(const QgsVertexId &other) const
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QgsVertexId(int _part=-1, int _ring=-1, int _vertex=-1, VertexType _type=SegmentVertex)
static QgsRectangle calculateBoundingBox(QGis::WkbType wkbType, const unsigned char *wkb, size_t numPoints)
Returns the BBOX of the specified WKB-point stream.
virtual double length() const
Returns the length of the geometry.
Multi curve geometry collection.
Abstract base class for all geometries.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
Multi point geometry collection.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
Utility class for identifying a unique vertex within a geometry.
Point geometry type.
Definition: qgspointv2.h:29
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
bool vertexEqual(const QgsVertexId &o) const
virtual QgsAbstractGeometryV2 * segmentize() const
Returns a version of the geometry without curves.
virtual int ringCount(int part=0) const =0
bool ringEqual(const QgsVertexId &o) const
virtual double area() const
Returns the area of the geometry.
Class for doing transforms between two map coordinate systems.
bool isValid() const
Returns true if the vertex id is valid.
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'.
virtual double perimeter() const
Returns the perimeter of the geometry.
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
bool isValid(const QgsAbstractGeometryV2 *geom) const
bool operator!=(const QgsVertexId &other) const
bool partEqual(const QgsVertexId &o) const