Skip to content

Commit dbfe808

Browse files
author
wonder
committed
Added missing QgsGeometry::contains predicate.
Contributed by Jeremy Palmer (#2560). git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13065 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 73483c4 commit dbfe808

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

python/core/qgsgeometry.sip

+4
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ not disjoint with existing polygons of the feature*/
238238

239239
/** Test for containment of a point (uses GEOS) */
240240
bool contains(QgsPoint* p);
241+
242+
/** Test for containment with a geometry (uses GEOS)
243+
* @note added in 1.5 */
244+
bool contains( QgsGeometry* geometry );
241245

242246
/** Returns a buffer region around this geometry having the given width and with a specified number
243247
of segments used to approximate curves */

src/core/qgsgeometry.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -3751,6 +3751,23 @@ bool QgsGeometry::contains( QgsPoint* p )
37513751
return returnval;
37523752
}
37533753

3754+
bool QgsGeometry::contains( QgsGeometry* geometry )
3755+
{
3756+
try // geos might throw exception on error
3757+
{
3758+
// ensure that both geometries have geos geometry
3759+
exportWkbToGeos();
3760+
geometry->exportWkbToGeos();
3761+
3762+
if ( !mGeos || !geometry->mGeos )
3763+
{
3764+
QgsDebugMsg( "GEOS geometry not available!" );
3765+
return false;
3766+
}
3767+
return GEOSContains( mGeos, geometry->mGeos );
3768+
}
3769+
CATCH_GEOS( false )
3770+
}
37543771

37553772
QString QgsGeometry::exportToWkt()
37563773
{

src/core/qgsgeometry.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,16 @@ class CORE_EXPORT QgsGeometry
276276

277277
/** Test for intersection with a rectangle (uses GEOS) */
278278
bool intersects( const QgsRectangle& r );
279-
/** Test for intersection with a geoemetry (uses GEOS) */
279+
/** Test for intersection with a geometry (uses GEOS) */
280280
bool intersects( QgsGeometry* geometry );
281281

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

285+
/** Test for containment with a geometry (uses GEOS)
286+
* @note added in 1.5 */
287+
bool contains( QgsGeometry* geometry );
288+
285289
/** Returns a buffer region around this geometry having the given width and with a specified number
286290
of segments used to approximate curves */
287291
QgsGeometry* buffer( double distance, int segments );

0 commit comments

Comments
 (0)