Navigation Menu

Skip to content

Commit

Permalink
[FEATURE] support more GEOS operators
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13366 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 24, 2010
1 parent 87936d9 commit e946ed1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 11 deletions.
61 changes: 53 additions & 8 deletions src/core/qgsgeometry.cpp
Expand Up @@ -3751,24 +3751,62 @@ bool QgsGeometry::contains( QgsPoint* p )
return returnval;
}

bool QgsGeometry::contains( QgsGeometry* geometry )
bool QgsGeometry::geosRelOp(
char GEOS_DLL( *op )( const GEOSGeometry*, const GEOSGeometry * ),
QgsGeometry *a,
QgsGeometry *b )
{
try // geos might throw exception on error
{
// ensure that both geometries have geos geometry
exportWkbToGeos();
geometry->exportWkbToGeos();
a->exportWkbToGeos();
b->exportWkbToGeos();

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

bool QgsGeometry::contains( QgsGeometry* geometry )
{
return geosRelOp( GEOSContains, this, geometry );
}

bool QgsGeometry::disjoint( QgsGeometry* geometry )
{
return geosRelOp( GEOSDisjoint, this, geometry );
}

bool QgsGeometry::equals( QgsGeometry* geometry )
{
return geosRelOp( GEOSEquals, this, geometry );
}

bool QgsGeometry::touches( QgsGeometry* geometry )
{
return geosRelOp( GEOSTouches, this, geometry );
}

bool QgsGeometry::overlaps( QgsGeometry* geometry )
{
return geosRelOp( GEOSOverlaps, this, geometry );
}

bool QgsGeometry::within( QgsGeometry* geometry )
{
return geosRelOp( GEOSWithin, this, geometry );
}

bool QgsGeometry::crosses( QgsGeometry* geometry )
{
return geosRelOp( GEOSCrosses, this, geometry );
}

QString QgsGeometry::exportToWkt()
{
QgsDebugMsg( "entered." );
Expand Down Expand Up @@ -6541,13 +6579,20 @@ bool QgsGeometry::isGeosValid()
}

bool QgsGeometry::isGeosEqual( QgsGeometry &g )
{
return geosRelOp( GEOSEquals, this, &g );
}

bool QgsGeometry::isGeosEmpty()
{
try
{
GEOSGeometry *g0 = asGeos();
GEOSGeometry *g1 = g.asGeos();
GEOSGeometry *g = asGeos();

if ( !g )
return false;

return g0 && g1 && GEOSEquals( g0, g1 );
return GEOSisEmpty( g );
}
catch ( GEOSException &e )
{
Expand Down
36 changes: 35 additions & 1 deletion src/core/qgsgeometry.h
Expand Up @@ -141,6 +141,11 @@ class CORE_EXPORT QgsGeometry
*/
bool isGeosValid();

/** check if geometry is empty using GEOS
@note added in 1.5
*/
bool isGeosEmpty();

double distance( QgsGeometry& geom );

/**
Expand Down Expand Up @@ -276,16 +281,41 @@ class CORE_EXPORT QgsGeometry

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

/** 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)
/** Test for if geometry is contain in an other (uses GEOS)
* @note added in 1.5 */
bool contains( QgsGeometry* geometry );

/** Test for if geometry is disjoint of an other (uses GEOS)
* @note added in 1.5 */
bool disjoint( QgsGeometry* geometry );

/** Test for if geometry equals an other (uses GEOS)
* @note added in 1.5 */
bool equals( QgsGeometry* geometry );

/** Test for if geometry touch an other (uses GEOS)
* @note added in 1.5 */
bool touches( QgsGeometry* geometry );

/** Test for if geometry overlaps an other (uses GEOS)
* @note added in 1.5 */
bool overlaps( QgsGeometry* geometry );

/** Test for if geometry is within an other (uses GEOS)
* @note added in 1.5 */
bool within( QgsGeometry* geometry );

/** Test for if geometry crosses an other (uses GEOS)
* @note added in 1.5 */
bool crosses( 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 Expand Up @@ -526,6 +556,10 @@ class CORE_EXPORT QgsGeometry
int p0, int i0, const QgsPolyline &ring0,
int p1, int i1, const QgsPolyline &ring1 );

static bool geosRelOp( char GEOS_DLL( *op )( const GEOSGeometry*, const GEOSGeometry * ),
QgsGeometry *a, QgsGeometry *b );


static int refcount;
}; // class QgsGeometry

Expand Down
2 changes: 0 additions & 2 deletions src/core/spatialindex/include/PoolPointer.h
Expand Up @@ -22,8 +22,6 @@
#ifndef __tools_pool_pointer_h
#define __tools_pool_pointer_h

#include "PointerPool.h"

namespace Tools
{
template <class X> class PointerPool;
Expand Down

0 comments on commit e946ed1

Please sign in to comment.