Skip to content

Commit

Permalink
#9480: New 'pointOnSurface' method for QgsGeometry
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed May 27, 2014
1 parent 20015e7 commit cbee3d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsgeometry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ class QgsGeometry
* and for point based geometries, the point itself is returned */
QgsGeometry* centroid() /Factory/;

/** Returns a point within a geometry */
QgsGeometry* pointOnSurface();

/** Returns the smallest convex polygon that contains all the points in the geometry. */
QgsGeometry* convexHull() /Factory/;

Expand Down
16 changes: 16 additions & 0 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ static GEOSInit geosinit;
#define GEOSArea(g, a) GEOSArea( (GEOSGeometry*) g, a )
#define GEOSTopologyPreserveSimplify(g, t) GEOSTopologyPreserveSimplify( (GEOSGeometry*) g, t )
#define GEOSGetCentroid(g) GEOSGetCentroid( (GEOSGeometry*) g )
#define GEOSPointOnSurface(g) GEOSPointOnSurface( (GEOSGeometry*) g )

#define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n )
#define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x )
Expand Down Expand Up @@ -5623,6 +5624,21 @@ QgsGeometry* QgsGeometry::centroid()
CATCH_GEOS( 0 )
}

QgsGeometry* QgsGeometry::pointOnSurface()
{
if ( mDirtyGeos )
exportWkbToGeos();

if ( !mGeos )
return 0;

try
{
return fromGeosGeom( GEOSPointOnSurface( mGeos ) );
}
CATCH_GEOS( 0 )
}

QgsGeometry* QgsGeometry::convexHull()
{
if ( mDirtyGeos )
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ class CORE_EXPORT QgsGeometry
* and for point based geometries, the point itself is returned */
QgsGeometry* centroid();

/** Returns a point within a geometry */
QgsGeometry* pointOnSurface();

/** Returns the smallest convex polygon that contains all the points in the geometry. */
QgsGeometry* convexHull();

Expand Down

0 comments on commit cbee3d3

Please sign in to comment.