Skip to content

Commit 91e93a3

Browse files
author
jef
committed
[FEATURE] support more GEOS operators
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13366 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 26ff0b3 commit 91e93a3

File tree

3 files changed

+88
-11
lines changed

3 files changed

+88
-11
lines changed

src/core/qgsgeometry.cpp

+53-8
Original file line numberDiff line numberDiff line change
@@ -3751,24 +3751,62 @@ bool QgsGeometry::contains( QgsPoint* p )
37513751
return returnval;
37523752
}
37533753

3754-
bool QgsGeometry::contains( QgsGeometry* geometry )
3754+
bool QgsGeometry::geosRelOp(
3755+
char GEOS_DLL( *op )( const GEOSGeometry*, const GEOSGeometry * ),
3756+
QgsGeometry *a,
3757+
QgsGeometry *b )
37553758
{
37563759
try // geos might throw exception on error
37573760
{
37583761
// ensure that both geometries have geos geometry
3759-
exportWkbToGeos();
3760-
geometry->exportWkbToGeos();
3762+
a->exportWkbToGeos();
3763+
b->exportWkbToGeos();
37613764

3762-
if ( !mGeos || !geometry->mGeos )
3765+
if ( !a->mGeos || !b->mGeos )
37633766
{
37643767
QgsDebugMsg( "GEOS geometry not available!" );
37653768
return false;
37663769
}
3767-
return GEOSContains( mGeos, geometry->mGeos );
3770+
return op( a->mGeos, b->mGeos );
37683771
}
37693772
CATCH_GEOS( false )
37703773
}
37713774

3775+
bool QgsGeometry::contains( QgsGeometry* geometry )
3776+
{
3777+
return geosRelOp( GEOSContains, this, geometry );
3778+
}
3779+
3780+
bool QgsGeometry::disjoint( QgsGeometry* geometry )
3781+
{
3782+
return geosRelOp( GEOSDisjoint, this, geometry );
3783+
}
3784+
3785+
bool QgsGeometry::equals( QgsGeometry* geometry )
3786+
{
3787+
return geosRelOp( GEOSEquals, this, geometry );
3788+
}
3789+
3790+
bool QgsGeometry::touches( QgsGeometry* geometry )
3791+
{
3792+
return geosRelOp( GEOSTouches, this, geometry );
3793+
}
3794+
3795+
bool QgsGeometry::overlaps( QgsGeometry* geometry )
3796+
{
3797+
return geosRelOp( GEOSOverlaps, this, geometry );
3798+
}
3799+
3800+
bool QgsGeometry::within( QgsGeometry* geometry )
3801+
{
3802+
return geosRelOp( GEOSWithin, this, geometry );
3803+
}
3804+
3805+
bool QgsGeometry::crosses( QgsGeometry* geometry )
3806+
{
3807+
return geosRelOp( GEOSCrosses, this, geometry );
3808+
}
3809+
37723810
QString QgsGeometry::exportToWkt()
37733811
{
37743812
QgsDebugMsg( "entered." );
@@ -6541,13 +6579,20 @@ bool QgsGeometry::isGeosValid()
65416579
}
65426580

65436581
bool QgsGeometry::isGeosEqual( QgsGeometry &g )
6582+
{
6583+
return geosRelOp( GEOSEquals, this, &g );
6584+
}
6585+
6586+
bool QgsGeometry::isGeosEmpty()
65446587
{
65456588
try
65466589
{
6547-
GEOSGeometry *g0 = asGeos();
6548-
GEOSGeometry *g1 = g.asGeos();
6590+
GEOSGeometry *g = asGeos();
6591+
6592+
if ( !g )
6593+
return false;
65496594

6550-
return g0 && g1 && GEOSEquals( g0, g1 );
6595+
return GEOSisEmpty( g );
65516596
}
65526597
catch ( GEOSException &e )
65536598
{

src/core/qgsgeometry.h

+35-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ class CORE_EXPORT QgsGeometry
141141
*/
142142
bool isGeosValid();
143143

144+
/** check if geometry is empty using GEOS
145+
@note added in 1.5
146+
*/
147+
bool isGeosEmpty();
148+
144149
double distance( QgsGeometry& geom );
145150

146151
/**
@@ -276,16 +281,41 @@ class CORE_EXPORT QgsGeometry
276281

277282
/** Test for intersection with a rectangle (uses GEOS) */
278283
bool intersects( const QgsRectangle& r );
284+
279285
/** Test for intersection with a geometry (uses GEOS) */
280286
bool intersects( QgsGeometry* geometry );
281287

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

285-
/** Test for containment with a geometry (uses GEOS)
291+
/** Test for if geometry is contain in an other (uses GEOS)
286292
* @note added in 1.5 */
287293
bool contains( QgsGeometry* geometry );
288294

295+
/** Test for if geometry is disjoint of an other (uses GEOS)
296+
* @note added in 1.5 */
297+
bool disjoint( QgsGeometry* geometry );
298+
299+
/** Test for if geometry equals an other (uses GEOS)
300+
* @note added in 1.5 */
301+
bool equals( QgsGeometry* geometry );
302+
303+
/** Test for if geometry touch an other (uses GEOS)
304+
* @note added in 1.5 */
305+
bool touches( QgsGeometry* geometry );
306+
307+
/** Test for if geometry overlaps an other (uses GEOS)
308+
* @note added in 1.5 */
309+
bool overlaps( QgsGeometry* geometry );
310+
311+
/** Test for if geometry is within an other (uses GEOS)
312+
* @note added in 1.5 */
313+
bool within( QgsGeometry* geometry );
314+
315+
/** Test for if geometry crosses an other (uses GEOS)
316+
* @note added in 1.5 */
317+
bool crosses( QgsGeometry* geometry );
318+
289319
/** Returns a buffer region around this geometry having the given width and with a specified number
290320
of segments used to approximate curves */
291321
QgsGeometry* buffer( double distance, int segments );
@@ -526,6 +556,10 @@ class CORE_EXPORT QgsGeometry
526556
int p0, int i0, const QgsPolyline &ring0,
527557
int p1, int i1, const QgsPolyline &ring1 );
528558

559+
static bool geosRelOp( char GEOS_DLL( *op )( const GEOSGeometry*, const GEOSGeometry * ),
560+
QgsGeometry *a, QgsGeometry *b );
561+
562+
529563
static int refcount;
530564
}; // class QgsGeometry
531565

src/core/spatialindex/include/PoolPointer.h

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#ifndef __tools_pool_pointer_h
2323
#define __tools_pool_pointer_h
2424

25-
#include "PointerPool.h"
26-
2725
namespace Tools
2826
{
2927
template <class X> class PointerPool;

0 commit comments

Comments
 (0)