QGIS API Documentation  2.14.0-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  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 
301  virtual double vertexAngle( QgsVertexId vertex ) const = 0;
302 
303  virtual int vertexCount( int part = 0, int ring = 0 ) const = 0;
304  virtual int ringCount( int part = 0 ) const = 0;
305 
310  virtual int partCount() const = 0;
311 
319  virtual bool addZValue( double zValue = 0 ) = 0;
320 
328  virtual bool addMValue( double mValue = 0 ) = 0;
329 
336  virtual bool dropZValue() = 0;
337 
344  virtual bool dropMValue() = 0;
345 
350  virtual bool convertTo( QgsWKBTypes::Type type );
351 
352  protected:
354 
357  void setZMTypeFromSubGeometry( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );
358 
362  virtual QgsRectangle calculateBoundingBox() const;
363 
366  virtual void clearCache() const {}
367 
368 };
369 
370 
376 struct CORE_EXPORT QgsVertexId
377 {
379  {
380  SegmentVertex = 1, //start / endpoint of a segment
381  CurveVertex
382  };
383 
384  QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
385  : part( _part ), ring( _ring ), vertex( _vertex ), type( _type ) {}
386 
389  bool isValid() const { return part >= 0 && ring >= 0 && vertex >= 0; }
390 
391  bool operator==( QgsVertexId other ) const
392  {
393  return part == other.part && ring == other.ring && vertex == other.vertex;
394  }
395  bool operator!=( QgsVertexId other ) const
396  {
397  return part != other.part || ring != other.ring || vertex != other.vertex;
398  }
399  bool partEqual( QgsVertexId o ) const
400  {
401  return part >= 0 && o.part == part;
402  }
403  bool ringEqual( QgsVertexId o ) const
404  {
405  return partEqual( o ) && ( ring >= 0 && o.ring == ring );
406  }
407  bool vertexEqual( QgsVertexId o ) const
408  {
409  return ringEqual( o ) && ( vertex >= 0 && o.ring == ring );
410  }
411  bool isValid( const QgsAbstractGeometryV2* geom ) const
412  {
413  return ( part >= 0 && part < geom->partCount() ) &&
414  ( ring < geom->ringCount( part ) ) &&
415  ( vertex < 0 || vertex < geom->vertexCount( part, ring ) );
416  }
417 
418  int part;
419  int ring;
420  int vertex;
422 };
423 
424 #endif //QGSABSTRACTGEOMETRYV2
QList< QgsPointV2 > QgsPointSequenceV2
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)
virtual double length() const
Returns the length of the geometry.
Multi curve geometry collection.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
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:61
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 operator==(QgsVertexId other) const
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
bool vertexEqual(QgsVertexId o) const
QList< QgsPointSequenceV2 > QgsRingSequenceV2
virtual QgsAbstractGeometryV2 * segmentize() const
Returns a version of the geometry without curves.
virtual int ringCount(int part=0) const =0
virtual double area() const
Returns the area of the geometry.
Class for doing transforms between two map coordinate systems.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, eg bounding boxes.
bool isValid() const
Returns true if the vertex id is valid.
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;.
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 partEqual(QgsVertexId o) const
bool operator!=(QgsVertexId other) const
bool ringEqual(QgsVertexId o) const