Skip to content
Permalink
Browse files

[FEATURE] support more GEOS operators

git-svn-id: http://svn.osgeo.org/qgis/trunk@13366 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Apr 24, 2010
1 parent 87936d9 commit e946ed199e41433ecf4b51d4d786009657d70bd5
Showing with 88 additions and 11 deletions.
  1. +53 −8 src/core/qgsgeometry.cpp
  2. +35 −1 src/core/qgsgeometry.h
  3. +0 −2 src/core/spatialindex/include/PoolPointer.h
@@ -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." );
@@ -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 )
{
@@ -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 );

/**
@@ -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 );
@@ -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

@@ -22,8 +22,6 @@
#ifndef __tools_pool_pointer_h
#define __tools_pool_pointer_h

#include "PointerPool.h"

namespace Tools
{
template <class X> class PointerPool;

0 comments on commit e946ed1

Please sign in to comment.
You can’t perform that action at this time.