Skip to content

Commit 2d9115f

Browse files
committedAug 1, 2012
- GEOSInterpolate only available in GEOS>=3.2
- sync QgsGeometry sip bindings with C++
1 parent a4670f0 commit 2d9115f

File tree

3 files changed

+142
-124
lines changed

3 files changed

+142
-124
lines changed
 

‎python/core/qgsgeometry.sip

Lines changed: 111 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
/** polyline is just a list of points */
2+
/** polyline is represented as a vector of points */
33
typedef QVector<QgsPoint> QgsPolyline;
44

55
/** polygon: first item of the list is outer ring, inner rings (if any) start from second item */
66
typedef QVector< QVector<QgsPoint> > QgsPolygon;
7-
7+
88
/** a collection of QgsPoints that share a common collection of attributes */
99
typedef QVector<QgsPoint> QgsMultiPoint;
1010

@@ -23,36 +23,34 @@ class QgsGeometry
2323
%End
2424

2525
public:
26-
2726
//! Constructor
2827
QgsGeometry();
29-
28+
3029
/** copy constructor will prompt a deep copy of the object */
3130
QgsGeometry( const QgsGeometry & );
32-
31+
3332

3433
//! Destructor
3534
~QgsGeometry();
3635

37-
3836
/** static method that creates geometry from Wkt */
39-
static QgsGeometry* fromWkt(QString wkt) /Factory/;
40-
37+
static QgsGeometry* fromWkt( QString wkt ) /Factory/;
38+
4139
/** construct geometry from a point */
42-
static QgsGeometry* fromPoint(const QgsPoint& point) /Factory/;
40+
static QgsGeometry* fromPoint( const QgsPoint& point ) /Factory/;
4341
/** construct geometry from a multipoint */
44-
static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint) /Factory/;
42+
static QgsGeometry* fromMultiPoint( const QgsMultiPoint& multipoint ) /Factory/;
4543
/** construct geometry from a polyline */
46-
static QgsGeometry* fromPolyline(const QgsPolyline& polyline) /Factory/;
44+
static QgsGeometry* fromPolyline( const QgsPolyline& polyline ) /Factory/;
4745
/** construct geometry from a multipolyline*/
48-
static QgsGeometry* fromMultiPolyline(const QgsMultiPolyline& multiline) /Factory/;
46+
static QgsGeometry* fromMultiPolyline( const QgsMultiPolyline& multiline ) /Factory/;
4947
/** construct geometry from a polygon */
50-
static QgsGeometry* fromPolygon(const QgsPolygon& polygon) /Factory/;
48+
static QgsGeometry* fromPolygon( const QgsPolygon& polygon ) /Factory/;
5149
/** construct geometry from a multipolygon */
52-
static QgsGeometry* fromMultiPolygon(const QgsMultiPolygon& multipoly) /Factory/;
50+
static QgsGeometry* fromMultiPolygon( const QgsMultiPolygon& multipoly ) /Factory/;
5351
/** construct geometry from a rectangle */
54-
static QgsGeometry* fromRect(const QgsRectangle& rect) /Factory/;
55-
52+
static QgsGeometry* fromRect( const QgsRectangle& rect ) /Factory/;
53+
5654

5755

5856
/**
@@ -77,10 +75,10 @@ class QgsGeometry
7775
%End
7876

7977
/**
80-
Returns the size of the WKB in asWkb().
81-
*/
78+
* Returns the size of the WKB in asWkb().
79+
*/
8280
size_t wkbSize();
83-
81+
8482
/** Returns type of wkb (point / linestring / polygon etc.) */
8583
QGis::WkbType wkbType();
8684

@@ -105,29 +103,24 @@ class QgsGeometry
105103
*/
106104
bool isGeosEmpty();
107105

108-
/**
109-
Set the geometry, feeding in a geometry in GEOS format.
110-
*/
111-
// TODO: unsupported class... would be possible to use PyGEOS?
112-
//void fromGeos(geos::Geometry* geos);
113-
114-
/** get area using GEOS
106+
/** get area of geometry using GEOS
115107
@note added in 1.5
116108
*/
117109
double area();
118110

119-
/** get length using GEOS
111+
/** get length of geometry using GEOS
120112
@note added in 1.5
121113
*/
122114
double length();
123115

124-
double distance(QgsGeometry& geom);
116+
double distance( QgsGeometry& geom );
125117

126118
/**
127-
Returns the vertex closest to the given point
128-
(and also vertex index, squared distance and indexes of the vertices before/after)
119+
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap point / target point
120+
and the indices of the vertices before/after. The vertices before/after are -1 if not present
129121
*/
130-
QgsPoint closestVertex(const QgsPoint& point, int& atVertex /Out/, int& beforeVertex /Out/, int& afterVertex /Out/, double& sqrDist /Out/);
122+
QgsPoint closestVertex( const QgsPoint& point, int& atVertex /Out/, int& beforeVertex /Out/, int& afterVertex /Out/, double& sqrDist /Out/);
123+
131124

132125
/**
133126
Returns the indexes of the vertices before and after the given vertex index.
@@ -141,120 +134,129 @@ class QgsGeometry
141134
account the first vertex is equal to the last vertex (and will
142135
skip equal vertex positions).
143136
*/
144-
void adjacentVertices(int atVertex, int& beforeVertex /Out/, int& afterVertex /Out/);
137+
void adjacentVertices( int atVertex, int& beforeVertex /Out/, int& afterVertex /Out/ );
138+
145139

146140
/** Insert a new vertex before the given vertex index,
147141
* ring and item (first number is index 0)
148142
* If the requested vertex number (beforeVertex.back()) is greater
149143
* than the last actual vertex on the requested ring and item,
150144
* it is assumed that the vertex is to be appended instead of inserted.
151-
* Returns FALSE if atVertex does not correspond to a valid vertex
145+
* Returns false if atVertex does not correspond to a valid vertex
152146
* on this geometry (including if this geometry is a Point).
153147
* It is up to the caller to distinguish between
154148
* these error conditions. (Or maybe we add another method to this
155149
* object to help make the distinction?)
156150
*/
157-
bool insertVertex(double x, double y, int beforeVertex);
151+
bool insertVertex( double x, double y, int beforeVertex );
158152

159-
/** Moves the vertex at the given position number,
160-
* ring and item (first number is index 0)
153+
/** Moves the vertex at the given position number
154+
* and item (first number is index 0)
161155
* to the given coordinates.
162-
* Returns FALSE if atVertex does not correspond to a valid vertex
163-
* on this geometry
156+
* Returns false if atVertex does not correspond to a valid vertex
157+
* on this geometry
164158
*/
165-
bool moveVertex(double x, double y, int atVertex);
166-
167-
/** Deletes the vertex at the given position number,
168-
* ring and item (first number is index 0)
169-
* Returns FALSE if atVertex does not correspond to a valid vertex
159+
bool moveVertex( double x, double y, int atVertex );
160+
161+
/** Deletes the vertex at the given position number and item
162+
* (first number is index 0)
163+
* Returns false if atVertex does not correspond to a valid vertex
170164
* on this geometry (including if this geometry is a Point),
171165
* or if the number of remaining verticies in the linestring
172166
* would be less than two.
173167
* It is up to the caller to distinguish between
174168
* these error conditions. (Or maybe we add another method to this
175169
* object to help make the distinction?)
176170
*/
177-
bool deleteVertex(int atVertex);
171+
bool deleteVertex( int atVertex );
178172

179173
/**
180174
* Returns coordinates of a vertex.
181175
* @param atVertex index of the vertex
182176
* @return Coordinates of the vertex or QgsPoint(0,0) on error
183177
*/
184-
QgsPoint vertexAt(int atVertex);
178+
QgsPoint vertexAt( int atVertex );
185179

186180
/**
187-
Returns the squared cartesian distance between the given point
188-
to the given vertex index*/
189-
double sqrDistToVertexAt(QgsPoint& point /In/, int atVertex);
181+
* Returns the squared cartesian distance between the given point
182+
* to the given vertex index (vertex at the given position number,
183+
* ring and item (first number is index 0))
184+
*/
185+
double sqrDistToVertexAt( QgsPoint& point /In/, int atVertex );
190186

191-
192-
/**
187+
/**
193188
* Searches for the the closest vertex in this geometry to the given point.
194189
* @param point Specifiest the point for search
195190
* @param atVertex Receives index of the closest vertex
196191
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
197192
*/
198-
double closestVertexWithContext(const QgsPoint& point, int& atVertex /Out/);
193+
double closestVertexWithContext( const QgsPoint& point, int& atVertex /Out/ );
199194

200195
/**
201196
* Searches for the closest segment of geometry to the given point
202197
* @param point Specifies the point for search
203198
* @param minDistPoint Receives the nearest point on the segment
204-
* @param beforeVertex Receives index of the vertex before the closest segment
199+
* @param afterVertex Receives index of the vertex after the closest segment. The vertex
200+
* before the closest segment is always afterVertex - 1
201+
* @param leftOf Out: Returns if the point lies on the left of right side of the segment ( < 0 means left, > 0 means right )
202+
* @param epsilon epsilon for segment snapping (added in 1.8)
205203
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
206204
*/
207-
double closestSegmentWithContext(const QgsPoint& point, QgsPoint& minDistPoint /Out/, int& beforeVertex /Out/);
205+
double closestSegmentWithContext( const QgsPoint& point, QgsPoint& minDistPoint /Out/, int& beforeVertex /Out/ );
208206

209-
/**Adds a new ring to this geometry. This makes only sense for polygon and multipolygons.
210-
@return 0 in case of success (ring added), 1 problem with geometry type, 2 ring not closed, \
207+
/**Adds a new ring to this geometry. This makes only sense for polygon and multipolygons.
208+
@return 0 in case of success (ring added), 1 problem with geometry type, 2 ring not closed,
211209
3 ring is not valid geometry, 4 ring not disjoint with existing rings, 5 no polygon found which contained the ring*/
212-
int addRing(const QList<QgsPoint>& ring);
210+
int addRing( const QList<QgsPoint>& ring );
213211

214-
/**Adds a new island polygon to a multipolygon feature
215-
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring \
216-
not disjoint with existing polygons of the feature*/
217-
int addPart(const QList<QgsPoint>& ring);
212+
/**Adds a new island polygon to a multipolygon feature
213+
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring
214+
not disjoint with existing polygons of the feature*/
215+
int addPart( const QList<QgsPoint>& ring );
218216
int addIsland( const QList<QgsPoint> &ring ) /Deprecated/;
219217

220-
/**Translate this geometry by dx, dy
218+
/**Translate this geometry by dx, dy
221219
@return 0 in case of success*/
222-
int translate(double dx, double dy);
220+
int translate( double dx, double dy );
223221

224-
/**Transform this geometry as described by CoordinateTranasform ct
222+
/**Transform this geometry as described by CoordinateTranasform ct
225223
@return 0 in case of success*/
226224
int transform( const QgsCoordinateTransform& ct );
227225

228-
/**Splits this geometry according to a given line. Note that the geometry is only split once. If there are several intersections
229-
between geometry and splitLine, only the first one is considered.
226+
/**Splits this geometry according to a given line. Note that the geometry is only split once. If there are several intersections
227+
between geometry and splitLine, only the first one is considered.
230228
@param splitLine the line that splits the geometry
231-
@param newGeometrys OUT: list of new geometries that have been created with the split
229+
@param[out] newGeometries list of new geometries that have been created with the split
232230
@param topological true if topological editing is enabled
233-
@topologyTestPoints OUT: points that need to be tested for topological completeness in the dataset
231+
@param[out] topologyTestPoints points that need to be tested for topological completeness in the dataset
234232
@return 0 in case of success, 1 if geometry has not been split, error else*/
235-
int splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeometry*>& newGeometries /Out/, bool topological, QList<QgsPoint>& topologyTestPoints /Out/);
233+
int splitGeometry( const QList<QgsPoint>& splitLine,
234+
QList<QgsGeometry*>&newGeometries /Out/,
235+
bool topological,
236+
QList<QgsPoint> &topologyTestPoints /Out/);
236237

237-
/**Replaces a part of this geometry with another line
238+
/**Replaces a part of this geometry with another line
238239
@return 0 in case of success
239240
@note: this function was added in version 1.3*/
240241
int reshapeGeometry( const QList<QgsPoint>& reshapeWithLine );
241242

242-
/**Changes this geometry such that it does not intersect the other geometry
243+
/**Changes this geometry such that it does not intersect the other geometry
243244
@param other geometry that should not be intersect
244245
@return 0 in case of success*/
245-
int makeDifference(QgsGeometry* other);
246+
int makeDifference( QgsGeometry* other );
246247

247248
/**Returns the bounding box of this feature*/
248249
QgsRectangle boundingBox();
249250

250251
/** Test for intersection with a rectangle (uses GEOS) */
251-
bool intersects(const QgsRectangle& r);
252-
/** Test for intersection with a geoemetry (uses GEOS) */
253-
bool intersects(QgsGeometry* geometry);
252+
bool intersects( const QgsRectangle& r );
253+
254+
/** Test for intersection with a geometry (uses GEOS) */
255+
bool intersects( QgsGeometry* geometry );
254256

255257
/** Test for containment of a point (uses GEOS) */
256-
bool contains(QgsPoint* p);
257-
258+
bool contains( QgsPoint* p );
259+
258260
/** Test for if geometry is contained in an other (uses GEOS)
259261
* @note added in 1.5 */
260262
bool contains( QgsGeometry* geometry );
@@ -285,11 +287,11 @@ not disjoint with existing polygons of the feature*/
285287

286288
/** Returns a buffer region around this geometry having the given width and with a specified number
287289
of segments used to approximate curves */
288-
QgsGeometry* buffer(double distance, int segments) /Factory/;
290+
QgsGeometry* buffer( double distance, int segments ) /Factory/;
289291

290292
/** Returns a simplified version of this geometry using a specified tolerance value */
291-
QgsGeometry* simplify(double tolerance) /Factory/;
292-
293+
QgsGeometry* simplify( double tolerance ) /Factory/;
294+
293295
/** Returns the center of mass of a geometry
294296
* @note for line based geometries, the center point of the line is returned,
295297
* and for point based geometries, the point itself is returned */
@@ -298,53 +300,59 @@ not disjoint with existing polygons of the feature*/
298300
/** Returns the smallest convex polygon that contains all the points in the geometry. */
299301
QgsGeometry* convexHull() /Factory/;
300302

303+
/* Return interpolated point on line at distance
304+
* @note added in 1.9
305+
*/
301306
QgsGeometry* interpolate( double distance ) /Factory/;
302-
307+
303308
/** Returns a geometry representing the points shared by this geometry and other. */
304-
QgsGeometry* intersection(QgsGeometry* geometry) /Factory/;
305-
309+
QgsGeometry* intersection( QgsGeometry* geometry ) /Factory/;
310+
306311
/** Returns a geometry representing all the points in this geometry and other (a
307-
* union geometry operation).
312+
* union geometry operation).
308313
* @note this operation is not called union since its a reserved word in C++.*/
309314
QgsGeometry* combine( QgsGeometry* geometry ) /Factory/;
310-
315+
311316
/** Returns a geometry representing the points making up this geometry that do not make up other. */
312-
QgsGeometry* difference(QgsGeometry* geometry) /Factory/;
313-
317+
QgsGeometry* difference( QgsGeometry* geometry ) /Factory/;
318+
314319
/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
315-
QgsGeometry* symDifference(QgsGeometry* geometry) /Factory/;
316-
317-
/**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
318-
// TODO: unsupported class... would be possible to use PyGEOS?
319-
//geos::Geometry* geosGeometry() const;
320+
QgsGeometry* symDifference( QgsGeometry* geometry ) /Factory/;
320321

321322
/** Exports the geometry to mWkt
322-
@return true in case of success and false else
323+
* @return true in case of success and false else
323324
*/
324325
QString exportToWkt();
325-
326+
327+
/** Exports the geometry to mGeoJSON
328+
* @return true in case of success and false else
329+
* @note added in 1.8
330+
* @note python binding added in 1.9
331+
*/
332+
QString exportToGeoJSON();
333+
326334
/* Accessor functions for getting geometry data */
327-
335+
328336
/** return contents of the geometry as a point
329337
if wkbType is WKBPoint, otherwise returns [0,0] */
330338
QgsPoint asPoint();
331-
339+
332340
/** return contents of the geometry as a polyline
333341
if wkbType is WKBLineString, otherwise an empty list */
334342
QgsPolyline asPolyline();
335-
343+
336344
/** return contents of the geometry as a polygon
337345
if wkbType is WKBPolygon, otherwise an empty list */
338346
QgsPolygon asPolygon();
339-
347+
340348
/** return contents of the geometry as a multi point
341-
if wkbType is WKBMultiPint, otherwise an empty list */
349+
if wkbType is WKBMultiPoint, otherwise an empty list */
342350
QgsMultiPoint asMultiPoint();
343-
351+
344352
/** return contents of the geometry as a multi linestring
345353
if wkbType is WKBMultiLineString, otherwise an empty list */
346354
QgsMultiPolyline asMultiPolyline();
347-
355+
348356
/** return contents of the geometry as a multi polygon
349357
if wkbType is WKBMultiPolygon, otherwise an empty list */
350358
QgsMultiPolygon asMultiPolygon();
@@ -356,12 +364,12 @@ not disjoint with existing polygons of the feature*/
356364

357365
/** delete a ring in polygon or multipolygon.
358366
Ring 0 is outer ring and can't be deleted.
359-
@return TRUE on success
367+
@return true on success
360368
@note added in version 1.2 */
361369
bool deleteRing( int ringNum, int partNum = 0 );
362370

363371
/** delete part identified by the part number
364-
@return TRUE on success
372+
@return true on success
365373
@note added in version 1.2 */
366374
bool deletePart( int partNum );
367375

@@ -388,7 +396,7 @@ not disjoint with existing polygons of the feature*/
388396
QgsPoint where();
389397
bool hasWhere();
390398
};
391-
399+
392400
/** Validate geometry and produce a list of geometry errors
393401
* @note python binding added in 1.6
394402
**/

‎src/core/qgsgeometry.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6411,20 +6411,25 @@ QgsGeometry* QgsGeometry::convexHull()
64116411

64126412
QgsGeometry* QgsGeometry::interpolate( double distance )
64136413
{
6414-
if ( !mGeos )
6415-
{
6416-
exportWkbToGeos();
6417-
}
6418-
if ( !mGeos )
6419-
{
6420-
return 0;
6421-
}
6414+
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
6415+
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=2)))
6416+
if ( !mGeos )
6417+
{
6418+
exportWkbToGeos();
6419+
}
6420+
if ( !mGeos )
6421+
{
6422+
return 0;
6423+
}
64226424

6423-
try
6424-
{
6425-
return fromGeosGeom( GEOSInterpolate( mGeos, distance ) );
6426-
}
6427-
CATCH_GEOS( 0 )
6425+
try
6426+
{
6427+
return fromGeosGeom( GEOSInterpolate( mGeos, distance ) );
6428+
}
6429+
CATCH_GEOS( 0 )
6430+
#else
6431+
QgsMessageLog::logMessage( QObject::tr( "GEOS prior to 3.2 doesn't support GEOSInterpolate" ), QObject::tr( "GEOS" ) );
6432+
#endif
64286433
}
64296434

64306435
QgsGeometry* QgsGeometry::intersection( QgsGeometry* geometry )

‎src/core/qgsgeometry.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class CORE_EXPORT QgsGeometry
113113
unsigned char * asWkb();
114114

115115
/**
116-
Returns the size of the WKB in asWkb().
117-
*/
116+
* Returns the size of the WKB in asWkb().
117+
*/
118118
size_t wkbSize();
119119

120120
/**Returns a geos geomtry. QgsGeometry keeps ownership, don't delete the returned object!
@@ -220,10 +220,9 @@ class CORE_EXPORT QgsGeometry
220220
QgsPoint vertexAt( int atVertex );
221221

222222
/**
223-
Returns the squared cartesian distance between the given point
224-
to the given vertex index (vertex at the given position number,
225-
ring and item (first number is index 0))
226-
223+
* Returns the squared cartesian distance between the given point
224+
* to the given vertex index (vertex at the given position number,
225+
* ring and item (first number is index 0))
227226
*/
228227
double sqrDistToVertexAt( QgsPoint& point, int atVertex );
229228

@@ -343,6 +342,9 @@ class CORE_EXPORT QgsGeometry
343342
/** Returns the smallest convex polygon that contains all the points in the geometry. */
344343
QgsGeometry* convexHull();
345344

345+
/* Return interpolated point on line at distance
346+
* @note added in 1.9
347+
*/
346348
QgsGeometry* interpolate( double distance );
347349

348350
/** Returns a geometry representing the points shared by this geometry and other. */
@@ -360,12 +362,14 @@ class CORE_EXPORT QgsGeometry
360362
QgsGeometry* symDifference( QgsGeometry* geometry );
361363

362364
/** Exports the geometry to mWkt
363-
@return true in case of success and false else
365+
* @return true in case of success and false else
364366
*/
365367
QString exportToWkt();
366368

367369
/** Exports the geometry to mGeoJSON
368-
@return true in case of success and false else
370+
* @return true in case of success and false else
371+
* @note added in 1.8
372+
* @note python binding added in 1.9
369373
*/
370374
QString exportToGeoJSON();
371375

@@ -441,6 +445,7 @@ class CORE_EXPORT QgsGeometry
441445

442446
/** Validate geometry and produce a list of geometry errors
443447
* @note added in 1.5
448+
* @note python binding added in 1.6
444449
**/
445450
void validateGeometry( QList<Error> &errors );
446451

0 commit comments

Comments
 (0)
Please sign in to comment.