Skip to content

Commit cbee3d3

Browse files
committed
#9480: New 'pointOnSurface' method for QgsGeometry
1 parent 20015e7 commit cbee3d3

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

python/core/qgsgeometry.sip

+3
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ class QgsGeometry
322322
* and for point based geometries, the point itself is returned */
323323
QgsGeometry* centroid() /Factory/;
324324

325+
/** Returns a point within a geometry */
326+
QgsGeometry* pointOnSurface();
327+
325328
/** Returns the smallest convex polygon that contains all the points in the geometry. */
326329
QgsGeometry* convexHull() /Factory/;
327330

src/core/qgsgeometry.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ static GEOSInit geosinit;
145145
#define GEOSArea(g, a) GEOSArea( (GEOSGeometry*) g, a )
146146
#define GEOSTopologyPreserveSimplify(g, t) GEOSTopologyPreserveSimplify( (GEOSGeometry*) g, t )
147147
#define GEOSGetCentroid(g) GEOSGetCentroid( (GEOSGeometry*) g )
148+
#define GEOSPointOnSurface(g) GEOSPointOnSurface( (GEOSGeometry*) g )
148149

149150
#define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n )
150151
#define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x )
@@ -5623,6 +5624,21 @@ QgsGeometry* QgsGeometry::centroid()
56235624
CATCH_GEOS( 0 )
56245625
}
56255626

5627+
QgsGeometry* QgsGeometry::pointOnSurface()
5628+
{
5629+
if ( mDirtyGeos )
5630+
exportWkbToGeos();
5631+
5632+
if ( !mGeos )
5633+
return 0;
5634+
5635+
try
5636+
{
5637+
return fromGeosGeom( GEOSPointOnSurface( mGeos ) );
5638+
}
5639+
CATCH_GEOS( 0 )
5640+
}
5641+
56265642
QgsGeometry* QgsGeometry::convexHull()
56275643
{
56285644
if ( mDirtyGeos )

src/core/qgsgeometry.h

+3
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ class CORE_EXPORT QgsGeometry
363363
* and for point based geometries, the point itself is returned */
364364
QgsGeometry* centroid();
365365

366+
/** Returns a point within a geometry */
367+
QgsGeometry* pointOnSurface();
368+
366369
/** Returns the smallest convex polygon that contains all the points in the geometry. */
367370
QgsGeometry* convexHull();
368371

0 commit comments

Comments
 (0)