Skip to content

Commit ded11b3

Browse files
committed
More geometry docs
1 parent df0b842 commit ded11b3

11 files changed

+381
-25
lines changed

src/core/geometry/qgsabstractgeometryv2.h

+197-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class QgsConstWkbPtr;
3030
class QgsWkbPtr;
3131
class QPainter;
3232

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+
*/
3338
struct CORE_EXPORT QgsVertexId
3439
{
3540
enum VertexType
@@ -41,7 +46,11 @@ struct CORE_EXPORT QgsVertexId
4146
QgsVertexId(): part( - 1 ), ring( -1 ), vertex( -1 ), type( SegmentVertex ) {}
4247
QgsVertexId( int _part, int _ring, int _vertex, VertexType _type = SegmentVertex )
4348
: part( _part ), ring( _ring ), vertex( _vertex ), type( _type ) {}
49+
50+
/** Returns true if the vertex id is valid
51+
*/
4452
bool isValid() const { return part >= 0 && ring >= 0 && vertex >= 0; }
53+
4554
bool operator==( const QgsVertexId& other )
4655
{
4756
return part == other.part && ring == other.ring && vertex == other.vertex;
@@ -57,7 +66,11 @@ struct CORE_EXPORT QgsVertexId
5766
VertexType type;
5867
};
5968

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+
*/
6174
class CORE_EXPORT QgsAbstractGeometryV2
6275
{
6376
public:
@@ -66,18 +79,56 @@ class CORE_EXPORT QgsAbstractGeometryV2
6679
QgsAbstractGeometryV2( const QgsAbstractGeometryV2& geom );
6780
virtual QgsAbstractGeometryV2& operator=( const QgsAbstractGeometryV2& geom );
6881

82+
/** Clones the geometry by performing a deep copy
83+
*/
6984
virtual QgsAbstractGeometryV2* clone() const = 0;
85+
86+
/** Clears the geometry, ie reset it to a null geometry
87+
*/
7088
virtual void clear() = 0;
7189

90+
/** Returns the minimal bounding box for the geometry
91+
*/
7292
QgsRectangle boundingBox() const;
7393

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+
7499
//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+
*/
75103
virtual int dimension() const = 0;
76104
//virtual int coordDim() const { return mCoordDimension; }
105+
106+
/** Returns a unique string representing the geometry type.
107+
* @see wkbType
108+
* @see wktTypeStr
109+
*/
77110
virtual QString geometryType() const = 0;
111+
112+
/** Returns the WKB type of the geometry.
113+
* @see geometryType
114+
* @see wktTypeStr
115+
*/
78116
QgsWKBTypes::Type wkbType() const { return mWkbType; }
117+
118+
/** Returns the WKT type string of the geometry.
119+
* @see geometryType
120+
* @see wkbType
121+
*/
79122
QString wktTypeStr() const;
123+
124+
/** Returns true if the geometry is 3D and contains a z-value.
125+
* @see isMeasure
126+
*/
80127
bool is3D() const;
128+
129+
/** Returns true if the geometry contains m values.
130+
* @see is3D
131+
*/
81132
bool isMeasure() const;
82133

83134
#if 0
@@ -92,56 +143,194 @@ class CORE_EXPORT QgsAbstractGeometryV2
92143
#endif
93144

94145
//import
146+
147+
/** Sets the geometry from a WKB string.
148+
* @see fromWkt
149+
*/
95150
virtual bool fromWkb( const unsigned char * wkb ) = 0;
151+
152+
/** Sets the geometry from a WKT string.
153+
* @see fromWkb
154+
*/
96155
virtual bool fromWkt( const QString& wkt ) = 0;
97156

98157
//export
158+
159+
/** Returns the size of the WKB representation of the geometry.
160+
* @see asWkb
161+
*/
99162
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+
*/
100172
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+
*/
101181
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+
*/
102192
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+
*/
103203
virtual QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const = 0;
104-
virtual QString asJSON( int precision = 17 ) const = 0;
105204

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;
107213

108214
//render pipeline
215+
216+
/** Transforms the geometry using a coordinate transform
217+
* @param ct coordinate transform
218+
*/
109219
virtual void transform( const QgsCoordinateTransform& ct ) = 0;
220+
221+
/** Transforms the geometry using a QTransform object
222+
* @param t QTransform transformation
223+
*/
110224
virtual void transform( const QTransform& t ) = 0;
225+
226+
#if 0
111227
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+
*/
112233
virtual void draw( QPainter& p ) const = 0;
113234

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+
*/
116241
virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const = 0;
117242

243+
/** Retrieves the sequence of geometries, rings and nodes.
244+
* @param coord destination for coordinate sequence.
245+
*/
118246
virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord ) const = 0;
247+
248+
/** Returns the number of nodes contained in the geometry
249+
*/
119250
int nCoordinates() const;
251+
252+
/** Returns the point corresponding to a specified vertex id
253+
*/
120254
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;
122265

123266
//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+
*/
124275
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+
*/
125284
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+
*/
126292
virtual bool deleteVertex( const QgsVertexId& position ) = 0;
127293

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+
*/
129297
virtual double length() const { return 0.0; }
298+
299+
/** Returns the area of the geometry.
300+
* @see length
301+
*/
130302
virtual double area() const { return 0.0; }
131303

304+
/** Returns true if the geometry is empty
305+
*/
132306
bool isEmpty() const;
133307

308+
/** Returns true if the geometry contains curved segments
309+
*/
134310
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+
*/
136315
virtual QgsAbstractGeometryV2* segmentize() const { return clone(); }
137316

138317
protected:
139318
QgsWKBTypes::Type mWkbType;
140319
mutable QgsRectangle mBoundingBox;
141320

321+
/** Updates the geometry type based on whether sub geometries contain z or m values.
322+
*/
142323
void setZMTypeFromSubGeometry( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );
143324

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+
*/
144332
static bool readWkbHeader( QgsConstWkbPtr& wkbPtr, QgsWKBTypes::Type& wkbType, bool& endianSwap, QgsWKBTypes::Type expectedType );
333+
145334
};
146335

147336
#endif //QGSABSTRACTGEOMETRYV2

src/core/geometry/qgscircularstringv2.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include "qgscurvev2.h"
2222
#include <QVector>
2323

24+
/**\ingroup core
25+
* \class QgsCircularStringV2
26+
* \brief Circular string geometry type
27+
* \note added in QGIS 2.10
28+
*/
2429
class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2
2530
{
2631
public:
@@ -45,10 +50,15 @@ class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2
4550
QString asJSON( int precision = 17 ) const override;
4651

4752
int numPoints() const override;
53+
54+
/** Returns the point at index i within the circular string.
55+
*/
4856
QgsPointV2 pointN( int i ) const;
4957
void points( QList<QgsPointV2>& pts ) const override;
50-
void setPoints( const QList<QgsPointV2>& points );
5158

59+
/** Sets the circular string's points
60+
*/
61+
void setPoints( const QList<QgsPointV2>& points );
5262

5363
//curve interface
5464
virtual double length() const override;

src/core/geometry/qgscompoundcurvev2.h

+21-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
#include "qgscurvev2.h"
2222

23+
/**\ingroup core
24+
* \class QgsCompoundCurveV2
25+
* \brief Compound curve geometry type
26+
* \note added in QGIS 2.10
27+
*/
2328
class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
2429
{
2530
public:
@@ -52,12 +57,26 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
5257
virtual void points( QList<QgsPointV2>& pts ) const override;
5358
virtual int numPoints() const override;
5459
virtual QgsLineStringV2* curveToLine() const override;
60+
61+
/** Returns the number of curves in the geometry.
62+
*/
5563
int nCurves() const { return mCurves.size(); }
64+
65+
/** Returns the curve at the specified index.
66+
*/
5667
const QgsCurveV2* curveAt( int i ) const;
5768

58-
/**Adds curve (takes ownership)*/
69+
/** Adds a curve to the geometr (takes ownership)
70+
*/
5971
void addCurve( QgsCurveV2* c );
72+
73+
/** Removes a curve from the geometry.
74+
* @param i index of curve to remove
75+
*/
6076
void removeCurve( int i );
77+
78+
/** Adds a vertex to the end of the geometry.
79+
*/
6180
void addVertex( const QgsPointV2& pt );
6281

6382
void draw( QPainter& p ) const override;
@@ -75,7 +94,7 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
7594

7695
void sumUpArea( double& sum ) const override;
7796

78-
/**Appends first point if not already closed*/
97+
/** Appends first point if not already closed.*/
7998
void close();
8099

81100
bool hasCurvedSegments() const override;

src/core/geometry/qgscurvepolygonv2.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
class QgsPolygonV2;
2424

25+
/**\ingroup core
26+
* \class QgsCurvePolygonV2
27+
* \brief Curve polygon geometry type
28+
* \note added in QGIS 2.10
29+
*/
2530
class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2
2631
{
2732
public:
@@ -62,8 +67,9 @@ class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2
6267

6368
/**Sets exterior ring (takes ownership)*/
6469
void setExteriorRing( QgsCurveV2* ring );
65-
/**Sets interior rings (takes ownership)*/
70+
/**Sets all interior rings (takes ownership)*/
6671
void setInteriorRings( QList<QgsCurveV2*> rings );
72+
/**Adds an interior ring to the geometry (takes ownership)*/
6773
void addInteriorRing( QgsCurveV2* ring );
6874
/**Removes ring. Exterior ring is 0, first interior ring 1, ...*/
6975
bool removeInteriorRing( int nr );

0 commit comments

Comments
 (0)