Skip to content

Commit

Permalink
Added missing QgsGeometry::contains predicate.
Browse files Browse the repository at this point in the history
Contributed by Jeremy Palmer (#2560).


git-svn-id: http://svn.osgeo.org/qgis/trunk@13065 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 17, 2010
1 parent 74141c9 commit 24b1c0b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/core/qgsgeometry.sip
Expand Up @@ -238,6 +238,10 @@ not disjoint with existing polygons of the feature*/

/** Test for containment of a point (uses GEOS) */
bool contains(QgsPoint* p);

/** Test for containment with a geometry (uses GEOS)
* @note added in 1.5 */
bool contains( QgsGeometry* geometry );

/** Returns a buffer region around this geometry having the given width and with a specified number
of segments used to approximate curves */
Expand Down
17 changes: 17 additions & 0 deletions src/core/qgsgeometry.cpp
Expand Up @@ -3751,6 +3751,23 @@ bool QgsGeometry::contains( QgsPoint* p )
return returnval;
}

bool QgsGeometry::contains( QgsGeometry* geometry )
{
try // geos might throw exception on error
{
// ensure that both geometries have geos geometry
exportWkbToGeos();
geometry->exportWkbToGeos();

if ( !mGeos || !geometry->mGeos )
{
QgsDebugMsg( "GEOS geometry not available!" );
return false;
}
return GEOSContains( mGeos, geometry->mGeos );
}
CATCH_GEOS( false )
}

QString QgsGeometry::exportToWkt()
{
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsgeometry.h
Expand Up @@ -276,12 +276,16 @@ class CORE_EXPORT QgsGeometry

/** Test for intersection with a rectangle (uses GEOS) */
bool intersects( const QgsRectangle& r );
/** Test for intersection with a geoemetry (uses GEOS) */
/** Test for intersection with a geometry (uses GEOS) */
bool intersects( QgsGeometry* geometry );

/** Test for containment of a point (uses GEOS) */
bool contains( QgsPoint* p );

/** Test for containment with a geometry (uses GEOS)
* @note added in 1.5 */
bool contains( QgsGeometry* geometry );

/** Returns a buffer region around this geometry having the given width and with a specified number
of segments used to approximate curves */
QgsGeometry* buffer( double distance, int segments );
Expand Down

0 comments on commit 24b1c0b

Please sign in to comment.