[QGIS Commit] r13366 - in trunk/qgis/src/core: . spatialindex/include

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Apr 24 14:08:00 EDT 2010


Author: jef
Date: 2010-04-24 14:07:59 -0400 (Sat, 24 Apr 2010)
New Revision: 13366

Modified:
   trunk/qgis/src/core/qgsgeometry.cpp
   trunk/qgis/src/core/qgsgeometry.h
   trunk/qgis/src/core/spatialindex/include/PoolPointer.h
Log:
[FEATURE] support more GEOS operators

Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp	2010-04-24 15:57:41 UTC (rev 13365)
+++ trunk/qgis/src/core/qgsgeometry.cpp	2010-04-24 18:07:59 UTC (rev 13366)
@@ -3751,24 +3751,62 @@
   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." );
@@ -6542,12 +6580,19 @@
 
 bool QgsGeometry::isGeosEqual( QgsGeometry &g )
 {
+  return geosRelOp( GEOSEquals, this, &g );
+}
+
+bool QgsGeometry::isGeosEmpty()
+{
   try
   {
-    GEOSGeometry *g0 = asGeos();
-    GEOSGeometry *g1 = g.asGeos();
+    GEOSGeometry *g = asGeos();
 
-    return g0 && g1 && GEOSEquals( g0, g1 );
+    if ( !g )
+      return false;
+
+    return GEOSisEmpty( g );
   }
   catch ( GEOSException &e )
   {

Modified: trunk/qgis/src/core/qgsgeometry.h
===================================================================
--- trunk/qgis/src/core/qgsgeometry.h	2010-04-24 15:57:41 UTC (rev 13365)
+++ trunk/qgis/src/core/qgsgeometry.h	2010-04-24 18:07:59 UTC (rev 13366)
@@ -141,6 +141,11 @@
      */
     bool isGeosValid();
 
+    /** check if geometry is empty using GEOS
+      @note added in 1.5
+     */
+    bool isGeosEmpty();
+
     double distance( QgsGeometry& geom );
 
     /**
@@ -276,16 +281,41 @@
 
     /** 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 @@
                                         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
 

Modified: trunk/qgis/src/core/spatialindex/include/PoolPointer.h
===================================================================
--- trunk/qgis/src/core/spatialindex/include/PoolPointer.h	2010-04-24 15:57:41 UTC (rev 13365)
+++ trunk/qgis/src/core/spatialindex/include/PoolPointer.h	2010-04-24 18:07:59 UTC (rev 13366)
@@ -22,8 +22,6 @@
 #ifndef __tools_pool_pointer_h
 #define __tools_pool_pointer_h
 
-#include "PointerPool.h"
-
 namespace Tools
 {
   template <class X> class PointerPool;



More information about the QGIS-commit mailing list