QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "qgsrectangle.h"
20 #include "qgswkbtypes.h"
21 #include <QString>
22 
24 class QgsMapToPixel;
25 class QgsCurveV2;
26 class QgsMultiCurveV2;
27 class QgsMultiPointV2;
28 class QgsPointV2;
29 class QgsConstWkbPtr;
30 class QgsWkbPtr;
31 class QPainter;
32 
39 struct CORE_EXPORT QgsVertexId
40 {
42  {
43  SegmentVertex = 1, //start / endpoint of a segment
44  CurveVertex
45  };
46 
47  QgsVertexId(): part( - 1 ), ring( -1 ), vertex( -1 ), type( SegmentVertex ) {}
48  QgsVertexId( int _part, int _ring, int _vertex, VertexType _type = SegmentVertex )
49  : part( _part ), ring( _ring ), vertex( _vertex ), type( _type ) {}
50 
53  bool isValid() const { return part >= 0 && ring >= 0 && vertex >= 0; }
54 
55  bool operator==( const QgsVertexId& other )
56  {
57  return part == other.part && ring == other.ring && vertex == other.vertex;
58  }
59  bool operator!=( const QgsVertexId& other )
60  {
61  return part != other.part || ring != other.ring || vertex != other.vertex;
62  }
63 
64  int part;
65  int ring;
66  int vertex;
68 };
69 
75 class CORE_EXPORT QgsAbstractGeometryV2
76 {
77  public:
79  virtual ~QgsAbstractGeometryV2();
81  virtual QgsAbstractGeometryV2& operator=( const QgsAbstractGeometryV2& geom );
82 
85  virtual QgsAbstractGeometryV2* clone() const = 0;
86 
89  virtual void clear() = 0;
90 
93  QgsRectangle boundingBox() const;
94 
98  virtual QgsRectangle calculateBoundingBox() const;
99 
100  //mm-sql interface
104  virtual int dimension() const = 0;
105  //virtual int coordDim() const { return mCoordDimension; }
106 
111  virtual QString geometryType() const = 0;
112 
117  QgsWKBTypes::Type wkbType() const { return mWkbType; }
118 
123  QString wktTypeStr() const;
124 
128  bool is3D() const;
129 
133  bool isMeasure() const;
134 
135 #if 0
136  virtual bool transform( const QgsCoordinateTransform& ct ) = 0;
137  virtual bool isEmpty() const = 0;
138  virtual bool isSimple() const = 0;
139  virtual bool isValid() const = 0;
140  virtual QgsMultiPointV2* locateAlong() const = 0;
141  virtual QgsMultiCurveV2* locateBetween() const = 0;
142  virtual QgsCurveV2* boundary() const = 0;
143  virtual QgsRectangle envelope() const = 0;
144 #endif
145 
146  //import
147 
151  virtual bool fromWkb( const unsigned char * wkb ) = 0;
152 
156  virtual bool fromWkt( const QString& wkt ) = 0;
157 
158  //export
159 
163  virtual int wkbSize() const = 0;
164 
173  virtual unsigned char* asWkb( int& binarySize ) const = 0;
174 
182  virtual QString asWkt( int precision = 17 ) const = 0;
183 
193  virtual QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
194 
204  virtual QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
205 
213  virtual QString asJSON( int precision = 17 ) const = 0;
214 
215  //render pipeline
216 
220  virtual void transform( const QgsCoordinateTransform& ct ) = 0;
221 
225  virtual void transform( const QTransform& t ) = 0;
226 
227 #if 0
228  virtual void clip( const QgsRectangle& rect ); //todo
229 #endif
230 
234  virtual void draw( QPainter& p ) const = 0;
235 
242  virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const = 0;
243 
247  virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord ) const = 0;
248 
251  int nCoordinates() const;
252 
255  QgsPointV2 vertexAt( const QgsVertexId& id ) const;
256 
265  virtual double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const = 0;
266 
267  //low-level editing
268 
276  virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex ) = 0;
277 
285  virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos ) = 0;
286 
293  virtual bool deleteVertex( const QgsVertexId& position ) = 0;
294 
298  virtual double length() const { return 0.0; }
299 
303  virtual double area() const { return 0.0; }
304 
307  bool isEmpty() const;
308 
311  virtual bool hasCurvedSegments() const { return false; }
312 
316  virtual QgsAbstractGeometryV2* segmentize() const { return clone(); }
317 
318  protected:
321 
324  void setZMTypeFromSubGeometry( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );
325 
333  static bool readWkbHeader( QgsConstWkbPtr& wkbPtr, QgsWKBTypes::Type& wkbType, bool& endianSwap, QgsWKBTypes::Type expectedType );
334 
335 };
336 
337 #endif //QGSABSTRACTGEOMETRYV2
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
static QgsRectangle calculateBoundingBox(QGis::WkbType wkbType, const unsigned char *wkb, size_t numPoints)
Returns the BBOX of the specified WKB-point stream.
QgsVertexId(int _part, int _ring, int _vertex, VertexType _type=SegmentVertex)
virtual double length() const
Returns the length (or perimeter for area geometries) of the geometry.
Multi curve geometry collection.
Abstract base class for all geometries.
Multi point geometry collection.
bool operator!=(const QgsVertexId &other)
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 operator==(const QgsVertexId &other)
virtual QgsAbstractGeometryV2 * segmentize() const
Returns a version of the geometry without curves.
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'.
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32