@@ -30,6 +30,11 @@ class QgsConstWkbPtr;
30
30
class QgsWkbPtr ;
31
31
class QPainter ;
32
32
33
+ /* *\ingroup core
34
+ * \class QgsVertexId
35
+ * \brief Utility class for identifying a unique vertex within a geometry.
36
+ * \note added in QGIS 2.10
37
+ */
33
38
struct CORE_EXPORT QgsVertexId
34
39
{
35
40
enum VertexType
@@ -41,7 +46,11 @@ struct CORE_EXPORT QgsVertexId
41
46
QgsVertexId (): part( - 1 ), ring( -1 ), vertex( -1 ), type( SegmentVertex ) {}
42
47
QgsVertexId ( int _part, int _ring, int _vertex, VertexType _type = SegmentVertex )
43
48
: part( _part ), ring( _ring ), vertex( _vertex ), type( _type ) {}
49
+
50
+ /* * Returns true if the vertex id is valid
51
+ */
44
52
bool isValid () const { return part >= 0 && ring >= 0 && vertex >= 0 ; }
53
+
45
54
bool operator ==( const QgsVertexId& other )
46
55
{
47
56
return part == other.part && ring == other.ring && vertex == other.vertex ;
@@ -57,7 +66,11 @@ struct CORE_EXPORT QgsVertexId
57
66
VertexType type;
58
67
};
59
68
60
- /* *Abstract base class for all geometries*/
69
+ /* *\ingroup core
70
+ * \class QgsAbstractGeometryV2
71
+ * \brief Abstract base class for all geometries
72
+ * \note added in QGIS 2.10
73
+ */
61
74
class CORE_EXPORT QgsAbstractGeometryV2
62
75
{
63
76
public:
@@ -66,18 +79,56 @@ class CORE_EXPORT QgsAbstractGeometryV2
66
79
QgsAbstractGeometryV2 ( const QgsAbstractGeometryV2& geom );
67
80
virtual QgsAbstractGeometryV2& operator =( const QgsAbstractGeometryV2& geom );
68
81
82
+ /* * Clones the geometry by performing a deep copy
83
+ */
69
84
virtual QgsAbstractGeometryV2* clone () const = 0;
85
+
86
+ /* * Clears the geometry, ie reset it to a null geometry
87
+ */
70
88
virtual void clear () = 0;
71
89
90
+ /* * Returns the minimal bounding box for the geometry
91
+ */
72
92
QgsRectangle boundingBox () const ;
73
93
94
+ /* * Calculates the minimal bounding box for the geometry. Derived classes should override this method
95
+ * to return the correct bounding box.
96
+ */
97
+ virtual QgsRectangle calculateBoundingBox () const ;
98
+
74
99
// mm-sql interface
100
+ /* * Returns the inherent dimension of the geometry. For example, this is 0 for a point geometry,
101
+ * 1 for a linestring and 2 for a polygon.
102
+ */
75
103
virtual int dimension () const = 0;
76
104
// virtual int coordDim() const { return mCoordDimension; }
105
+
106
+ /* * Returns a unique string representing the geometry type.
107
+ * @see wkbType
108
+ * @see wktTypeStr
109
+ */
77
110
virtual QString geometryType () const = 0;
111
+
112
+ /* * Returns the WKB type of the geometry.
113
+ * @see geometryType
114
+ * @see wktTypeStr
115
+ */
78
116
QgsWKBTypes::Type wkbType () const { return mWkbType ; }
117
+
118
+ /* * Returns the WKT type string of the geometry.
119
+ * @see geometryType
120
+ * @see wkbType
121
+ */
79
122
QString wktTypeStr () const ;
123
+
124
+ /* * Returns true if the geometry is 3D and contains a z-value.
125
+ * @see isMeasure
126
+ */
80
127
bool is3D () const ;
128
+
129
+ /* * Returns true if the geometry contains m values.
130
+ * @see is3D
131
+ */
81
132
bool isMeasure () const ;
82
133
83
134
#if 0
@@ -92,56 +143,194 @@ class CORE_EXPORT QgsAbstractGeometryV2
92
143
#endif
93
144
94
145
// import
146
+
147
+ /* * Sets the geometry from a WKB string.
148
+ * @see fromWkt
149
+ */
95
150
virtual bool fromWkb ( const unsigned char * wkb ) = 0;
151
+
152
+ /* * Sets the geometry from a WKT string.
153
+ * @see fromWkb
154
+ */
96
155
virtual bool fromWkt ( const QString& wkt ) = 0;
97
156
98
157
// export
158
+
159
+ /* * Returns the size of the WKB representation of the geometry.
160
+ * @see asWkb
161
+ */
99
162
virtual int wkbSize () const = 0;
163
+
164
+ /* * Returns a WKB representation of the geometry.
165
+ * @param binarySize will be set to the size of the returned WKB string
166
+ * @see wkbSize
167
+ * @see asWkt
168
+ * @see asGML2
169
+ * @see asGML3
170
+ * @see asJSON
171
+ */
100
172
virtual unsigned char * asWkb ( int & binarySize ) const = 0;
173
+
174
+ /* * Returns a WKT representation of the geometry.
175
+ * @param precision number of decimal places for coordinates
176
+ * @see asWkb
177
+ * @see asGML2
178
+ * @see asGML3
179
+ * @see asJSON
180
+ */
101
181
virtual QString asWkt ( int precision = 17 ) const = 0;
182
+
183
+ /* * Returns a GML2 representation of the geometry.
184
+ * @param doc DOM document
185
+ * @param precision number of decimal places for coordinates
186
+ * @param ns XML namespace
187
+ * @see asWkb
188
+ * @see asWkt
189
+ * @see asGML3
190
+ * @see asJSON
191
+ */
102
192
virtual QDomElement asGML2 ( QDomDocument& doc, int precision = 17 , const QString& ns = " gml" ) const = 0;
193
+
194
+ /* * Returns a GML3 representation of the geometry.
195
+ * @param doc DOM document
196
+ * @param precision number of decimal places for coordinates
197
+ * @param ns XML namespace
198
+ * @see asWkb
199
+ * @see asWkt
200
+ * @see asGML2
201
+ * @see asJSON
202
+ */
103
203
virtual QDomElement asGML3 ( QDomDocument& doc, int precision = 17 , const QString& ns = " gml" ) const = 0;
104
- virtual QString asJSON ( int precision = 17 ) const = 0;
105
204
106
- virtual QgsRectangle calculateBoundingBox () const ;
205
+ /* * Returns a GeoJSON representation of the geometry.
206
+ * @param precision number of decimal places for coordinates
207
+ * @see asWkb
208
+ * @see asWkt
209
+ * @see asGML2
210
+ * @see asGML3
211
+ */
212
+ virtual QString asJSON ( int precision = 17 ) const = 0;
107
213
108
214
// render pipeline
215
+
216
+ /* * Transforms the geometry using a coordinate transform
217
+ * @param ct coordinate transform
218
+ */
109
219
virtual void transform ( const QgsCoordinateTransform& ct ) = 0;
220
+
221
+ /* * Transforms the geometry using a QTransform object
222
+ * @param t QTransform transformation
223
+ */
110
224
virtual void transform ( const QTransform& t ) = 0;
225
+
226
+ #if 0
111
227
virtual void clip( const QgsRectangle& rect ) { Q_UNUSED( rect ); } //todo
228
+ #endif
229
+
230
+ /* * Draws the geometry using the specified QPainter.
231
+ * @param p destination QPainter
232
+ */
112
233
virtual void draw ( QPainter& p ) const = 0;
113
234
114
- /* *Returns next vertex id and coordinates
115
- @return false if at end*/
235
+ /* * Returns next vertex id and coordinates
236
+ * @param id initial value should be the starting vertex id. The next vertex id will be stored
237
+ * in this variable if found.
238
+ * @param vertex container for found node
239
+ * @return false if at end
240
+ */
116
241
virtual bool nextVertex ( QgsVertexId& id, QgsPointV2& vertex ) const = 0;
117
242
243
+ /* * Retrieves the sequence of geometries, rings and nodes.
244
+ * @param coord destination for coordinate sequence.
245
+ */
118
246
virtual void coordinateSequence ( QList< QList< QList< QgsPointV2 > > >& coord ) const = 0;
247
+
248
+ /* * Returns the number of nodes contained in the geometry
249
+ */
119
250
int nCoordinates () const ;
251
+
252
+ /* * Returns the point corresponding to a specified vertex id
253
+ */
120
254
QgsPointV2 vertexAt ( const QgsVertexId& id ) const ;
121
- virtual double closestSegment ( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool * leftOf, double epsilon ) const = 0;
255
+
256
+ /* * Searches for the closest segment of the geometry to a given point.
257
+ * @param pt Specifies the point for search
258
+ * @param segmentPt storage for the closest point within the geometry
259
+ * @param vertexAfter storage for the id of the vertex after the closest segment
260
+ * @param leftOf returns if the point lies on the left of right side of the segment ( < 0 means left, > 0 means right )
261
+ * @param epsilon epsilon for segment snapping
262
+ * @returns squared distance to closest segment
263
+ */
264
+ virtual double closestSegment ( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool * leftOf, double epsilon ) const = 0;
122
265
123
266
// low-level editing
267
+
268
+ /* * Inserts a vertex into the geometry
269
+ * @param position vertex id for position of inserted vertex
270
+ * @param vertex vertex to insert
271
+ * @returns true if insert was successful
272
+ * @see moveVertex
273
+ * @see deleteVertex
274
+ */
124
275
virtual bool insertVertex ( const QgsVertexId& position, const QgsPointV2& vertex ) = 0;
276
+
277
+ /* * Moves a vertex within the geometry
278
+ * @param position vertex id for vertex to move
279
+ * @param newPos new position of vertex
280
+ * @returns true if move was successful
281
+ * @see insertVertex
282
+ * @see deleteVertex
283
+ */
125
284
virtual bool moveVertex ( const QgsVertexId& position, const QgsPointV2& newPos ) = 0;
285
+
286
+ /* * Deletes a vertex within the geometry
287
+ * @param position vertex id for vertex to delete
288
+ * @returns true if delete was successful
289
+ * @see insertVertex
290
+ * @see moveVertex
291
+ */
126
292
virtual bool deleteVertex ( const QgsVertexId& position ) = 0;
127
293
128
- /* *Length for linear geometries,perimeter for area geometries*/
294
+ /* * Returns the length (or perimeter for area geometries) of the geometry.
295
+ * @see area
296
+ */
129
297
virtual double length () const { return 0.0 ; }
298
+
299
+ /* * Returns the area of the geometry.
300
+ * @see length
301
+ */
130
302
virtual double area () const { return 0.0 ; }
131
303
304
+ /* * Returns true if the geometry is empty
305
+ */
132
306
bool isEmpty () const ;
133
307
308
+ /* * Returns true if the geometry contains curved segments
309
+ */
134
310
virtual bool hasCurvedSegments () const { return false ; }
135
- /* *Returns a geometry without curves. Caller takes ownership*/
311
+
312
+ /* * Returns a version of the geometry without curves. Caller takes ownership of
313
+ * the returned geometry.
314
+ */
136
315
virtual QgsAbstractGeometryV2* segmentize () const { return clone (); }
137
316
138
317
protected:
139
318
QgsWKBTypes::Type mWkbType ;
140
319
mutable QgsRectangle mBoundingBox ;
141
320
321
+ /* * Updates the geometry type based on whether sub geometries contain z or m values.
322
+ */
142
323
void setZMTypeFromSubGeometry ( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );
143
324
325
+ /* * Reads a WKB header and tests its validity.
326
+ * @param wkbPtr
327
+ * @param wkbType destination for WKB type from header
328
+ * @param endianSwap will be set to true if endian from WKB must be swapped to match QGIS platform endianess
329
+ * @param expectedType expected WKB type
330
+ * @returns true if header is valid and matches expected type
331
+ */
144
332
static bool readWkbHeader ( QgsConstWkbPtr& wkbPtr, QgsWKBTypes::Type& wkbType, bool & endianSwap, QgsWKBTypes::Type expectedType );
333
+
145
334
};
146
335
147
336
#endif // QGSABSTRACTGEOMETRYV2
0 commit comments