2
/** polyline is just a list of points */
3
typedef QVector<QgsPoint> QgsPolyline;
5
/** polygon: first item of the list is outer ring, inner rings (if any) start from second item */
6
typedef QVector< QVector<QgsPoint> > QgsPolygon;
8
/** a collection of QgsPoints that share a common collection of attributes */
9
typedef QVector<QgsPoint> QgsMultiPoint;
11
/** a collection of QgsPolylines that share a common collection of attributes */
12
typedef QVector< QVector<QgsPoint> > QgsMultiPolyline;
14
/** a collection of QgsPolygons that share a common collection of attributes */
15
typedef QVector< QVector< QVector<QgsPoint> > > QgsMultiPolygon;
17
typedef unsigned int size_t;
22
#include <qgsgeometry.h>
30
/** copy constructor will prompt a deep copy of the object */
31
QgsGeometry( const QgsGeometry & );
38
/** static method that creates geometry from Wkt */
39
static QgsGeometry* fromWkt(QString wkt) /Factory/;
41
/** construct geometry from a point */
42
static QgsGeometry* fromPoint(const QgsPoint& point) /Factory/;
43
/** construct geometry from a multipoint */
44
static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint) /Factory/;
45
/** construct geometry from a polyline */
46
static QgsGeometry* fromPolyline(const QgsPolyline& polyline) /Factory/;
47
/** construct geometry from a multipolyline*/
48
static QgsGeometry* fromMultiPolyline(const QgsMultiPolyline& multiline) /Factory/;
49
/** construct geometry from a polygon */
50
static QgsGeometry* fromPolygon(const QgsPolygon& polygon) /Factory/;
51
/** construct geometry from a multipolygon */
52
static QgsGeometry* fromMultiPolygon(const QgsMultiPolygon& multipoly) /Factory/;
53
/** construct geometry from a rectangle */
54
static QgsGeometry* fromRect(const QgsRectangle& rect) /Factory/;
59
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
60
This class will take ownership of the buffer.
62
void fromWkb(unsigned char * wkb /Array/, size_t length /ArraySize/);
64
// create copy of Python's string and pass it to fromWkb()
65
unsigned char * copy = new unsigned char[a1];
67
sipCpp->fromWkb(copy, a1);
71
Returns the buffer containing this geometry in WKB format.
72
You may wish to use in conjunction with wkbSize().
76
sipRes = PyString_FromStringAndSize((const char *)sipCpp->asWkb(), sipCpp->wkbSize());
80
Returns the size of the WKB in asWkb().
84
/** Returns type of wkb (point / linestring / polygon etc.) */
85
QGis::WkbType wkbType();
87
/** Returns type of the vector */
88
QGis::GeometryType type();
90
/** Returns true if wkb of the geometry is of WKBMulti* type */
94
Set the geometry, feeding in a geometry in GEOS format.
96
// TODO: unsupported class... would be possible to use PyGEOS?
97
//void fromGeos(geos::Geometry* geos);
99
double distance(QgsGeometry& geom);
102
Returns the vertex closest to the given point
103
(and also vertex index, squared distance and indexes of the vertices before/after)
105
QgsPoint closestVertex(const QgsPoint& point, int& atVertex /Out/, int& beforeVertex /Out/, int& afterVertex /Out/, double& sqrDist /Out/);
108
Returns the indexes of the vertices before and after the given vertex index.
110
This function takes into account the following factors:
112
1. If the given vertex index is at the end of a linestring,
113
the adjacent index will be -1 (for "no adjacent vertex")
114
2. If the given vertex index is at the end of a linear ring
115
(such as in a polygon), the adjacent index will take into
116
account the first vertex is equal to the last vertex (and will
117
skip equal vertex positions).
119
void adjacentVertices(int atVertex, int& beforeVertex /Out/, int& afterVertex /Out/);
121
/** Insert a new vertex before the given vertex index,
122
* ring and item (first number is index 0)
123
* If the requested vertex number (beforeVertex.back()) is greater
124
* than the last actual vertex on the requested ring and item,
125
* it is assumed that the vertex is to be appended instead of inserted.
126
* Returns FALSE if atVertex does not correspond to a valid vertex
127
* on this geometry (including if this geometry is a Point).
128
* It is up to the caller to distinguish between
129
* these error conditions. (Or maybe we add another method to this
130
* object to help make the distinction?)
132
bool insertVertex(double x, double y, int beforeVertex);
134
/** Moves the vertex at the given position number,
135
* ring and item (first number is index 0)
136
* to the given coordinates.
137
* Returns FALSE if atVertex does not correspond to a valid vertex
140
bool moveVertex(double x, double y, int atVertex);
142
/** Deletes the vertex at the given position number,
143
* ring and item (first number is index 0)
144
* Returns FALSE if atVertex does not correspond to a valid vertex
145
* on this geometry (including if this geometry is a Point),
146
* or if the number of remaining verticies in the linestring
147
* would be less than two.
148
* It is up to the caller to distinguish between
149
* these error conditions. (Or maybe we add another method to this
150
* object to help make the distinction?)
152
bool deleteVertex(int atVertex);
155
* Returns coordinates of a vertex.
156
* @param atVertex index of the vertex
157
* @return Coordinates of the vertex or QgsPoint(0,0) on error
159
QgsPoint vertexAt(int atVertex);
162
Returns the squared cartesian distance between the given point
163
to the given vertex index*/
164
double sqrDistToVertexAt(QgsPoint& point /In/, int atVertex);
168
* Searches for the the closest vertex in this geometry to the given point.
169
* @param point Specifiest the point for search
170
* @param atVertex Receives index of the closest vertex
171
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
173
double closestVertexWithContext(const QgsPoint& point, int& atVertex /Out/);
176
* Searches for the closest segment of geometry to the given point
177
* @param point Specifies the point for search
178
* @param minDistPoint Receives the nearest point on the segment
179
* @param beforeVertex Receives index of the vertex before the closest segment
180
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
182
double closestSegmentWithContext(const QgsPoint& point, QgsPoint& minDistPoint /Out/, int& beforeVertex /Out/);
184
/**Adds a new ring to this geometry. This makes only sense for polygon and multipolygons.
185
@return 0 in case of success (ring added), 1 problem with geometry type, 2 ring not closed, \
186
3 ring is not valid geometry, 4 ring not disjoint with existing rings, 5 no polygon found which contained the ring*/
187
int addRing(const QList<QgsPoint>& ring);
189
/**Adds a new island polygon to a multipolygon feature
190
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring \
191
not disjoint with existing polygons of the feature*/
192
int addIsland(const QList<QgsPoint>& ring);
194
/**Translate this geometry by dx, dy
195
@return 0 in case of success*/
196
int translate(double dx, double dy);
198
/**Transform this geometry as described by CoordinateTranasform ct
199
@return 0 in case of success*/
200
int transform( const QgsCoordinateTransform& ct );
202
/**Splits this geometry according to a given line. Note that the geometry is only split once. If there are several intersections
203
between geometry and splitLine, only the first one is considered.
204
@param splitLine the line that splits the geometry
205
@param newGeometrys OUT: list of new geometries that have been created with the split
206
@param topological true if topological editing is enabled
207
@topologyTestPoints OUT: points that need to be tested for topological completeness in the dataset
208
@return 0 in case of success, 1 if geometry has not been split, error else*/
209
int splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeometry*>& newGeometries, bool topological, QList<QgsPoint>& topologyTestPoints);
211
/**Replaces a part of this geometry with another line
212
@return 0 in case of success
213
@note: this function was added in version 1.3*/
214
int reshapeGeometry( const QList<QgsPoint>& reshapeWithLine );
216
/**Changes this geometry such that it does not intersect the other geometry
217
@param other geometry that should not be intersect
218
@return 0 in case of success*/
219
int makeDifference(QgsGeometry* other);
221
/**Returns the bounding box of this feature*/
222
QgsRectangle boundingBox();
224
/** Test for intersection with a rectangle (uses GEOS) */
225
bool intersects(const QgsRectangle& r);
226
/** Test for intersection with a geoemetry (uses GEOS) */
227
bool intersects(QgsGeometry* geometry);
229
/** Test for containment of a point (uses GEOS) */
230
bool contains(QgsPoint* p);
232
/** Returns a buffer region around this geometry having the given width and with a specified number
233
of segments used to approximate curves */
234
QgsGeometry* buffer(double distance, int segments) /Factory/;
236
/** Returns a simplified version of this geometry using a specified tolerance value */
237
QgsGeometry* simplify(double tolerance) /Factory/;
239
/** Returns the center of mass of a geometry
240
* @note for line based geometries, the center point of the line is returned,
241
* and for point based geometries, the point itself is returned */
242
QgsGeometry* centroid() /Factory/;
244
/** Returns the smallest convex polygon that contains all the points in the geometry. */
245
QgsGeometry* convexHull() /Factory/;
247
/** Returns a geometry representing the points shared by this geometry and other. */
248
QgsGeometry* intersection(QgsGeometry* geometry) /Factory/;
250
/** Returns a geometry representing all the points in this geometry and other (a
251
* union geometry operation).
252
* @note this operation is not called union since its a reserved word in C++.*/
253
QgsGeometry* combine( QgsGeometry* geometry ) /Factory/;
255
/** Returns a geometry representing the points making up this geometry that do not make up other. */
256
QgsGeometry* difference(QgsGeometry* geometry) /Factory/;
258
/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
259
QgsGeometry* symDifference(QgsGeometry* geometry) /Factory/;
261
/**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
262
// TODO: unsupported class... would be possible to use PyGEOS?
263
//geos::Geometry* geosGeometry() const;
265
/** Exports the geometry to mWkt
266
@return true in case of success and false else
268
QString exportToWkt();
270
/* Accessor functions for getting geometry data */
272
/** return contents of the geometry as a point
273
if wkbType is WKBPoint, otherwise returns [0,0] */
276
/** return contents of the geometry as a polyline
277
if wkbType is WKBLineString, otherwise an empty list */
278
QgsPolyline asPolyline();
280
/** return contents of the geometry as a polygon
281
if wkbType is WKBPolygon, otherwise an empty list */
282
QgsPolygon asPolygon();
284
/** return contents of the geometry as a multi point
285
if wkbType is WKBMultiPint, otherwise an empty list */
286
QgsMultiPoint asMultiPoint();
288
/** return contents of the geometry as a multi linestring
289
if wkbType is WKBMultiLineString, otherwise an empty list */
290
QgsMultiPolyline asMultiPolyline();
292
/** return contents of the geometry as a multi polygon
293
if wkbType is WKBMultiPolygon, otherwise an empty list */
294
QgsMultiPolygon asMultiPolygon();
296
/** return contents of the geometry as a list of geometries
297
@note added in version 1.1 */
298
// TODO: destruction of created geometries??
299
QList<QgsGeometry*> asGeometryCollection() /Factory/;
301
/** delete a ring in polygon or multipolygon.
302
Ring 0 is outer ring and can't be deleted.
303
@return TRUE on success
304
@note added in version 1.2 */
305
bool deleteRing( int ringNum, int partNum = 0 );
307
/** delete part identified by the part number
308
@return TRUE on success
309
@note added in version 1.2 */
310
bool deletePart( int partNum );
312
/**Converts single type geometry into multitype geometry
313
e.g. a polygon into a multipolygon geometry with one polygon
314
@return true in case of success and false else*/
315
bool convertToMultiType();
317
}; // class QgsGeometry