[QGIS Commit] r9154 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Aug 24 12:29:31 EDT 2008


Author: jef
Date: 2008-08-24 12:29:31 -0400 (Sun, 24 Aug 2008)
New Revision: 9154

Modified:
   trunk/qgis/src/core/qgsgeometry.cpp
Log:
fix #1245

Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp	2008-08-24 15:56:41 UTC (rev 9153)
+++ trunk/qgis/src/core/qgsgeometry.cpp	2008-08-24 16:29:31 UTC (rev 9154)
@@ -42,22 +42,6 @@
     throw; \
   }
 
-#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
-#define GEOSGeom_clone(g) GEOSGeom_clone( (GEOSGeometry *) g )
-#define GEOSGeom_getCoordSeq(g) GEOSGeom_getCoordSeq( (GEOSGeometry *) g )
-#define GEOSGetExteriorRing(g) GEOSGetExteriorRing( (GEOSGeometry *)g )
-#define GEOSGetNumInteriorRings(g) GEOSGetNumInteriorRings( (GEOSGeometry *)g )
-#define GEOSGetInteriorRingN(g,i) GEOSGetInteriorRingN( (GEOSGeometry *)g, i )
-#define GEOSDisjoint(g0,g1) GEOSDisjoint( (GEOSGeometry *)g0, (GEOSGeometry*)g1 )
-#define GEOSIntersection(g0,g1) GEOSIntersection( (GEOSGeometry*) g0, (GEOSGeometry*)g1 )
-#define GEOSBuffer(g, d, s) GEOSBuffer( (GEOSGeometry*) g, d, s)
-#define GEOSArea(g, a) GEOSArea( (GEOSGeometry*) g, a)
-
-#define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n )
-#define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x )
-#define GEOSCoordSeq_getY(cs,i,y) GEOSCoordSeq_getY( (GEOSCoordSequence *)cs, i, y )
-#endif
-
 class GEOSException
 {
   public:
@@ -107,7 +91,54 @@
 #endif
 }
 
+#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
+#define GEOSGeom_getCoordSeq(g) GEOSGeom_getCoordSeq( (GEOSGeometry *) g )
+#define GEOSGetExteriorRing(g) GEOSGetExteriorRing( (GEOSGeometry *)g )
+#define GEOSGetNumInteriorRings(g) GEOSGetNumInteriorRings( (GEOSGeometry *)g )
+#define GEOSGetInteriorRingN(g,i) GEOSGetInteriorRingN( (GEOSGeometry *)g, i )
+#define GEOSDisjoint(g0,g1) GEOSDisjoint( (GEOSGeometry *)g0, (GEOSGeometry*)g1 )
+#define GEOSIntersection(g0,g1) GEOSIntersection( (GEOSGeometry*) g0, (GEOSGeometry*)g1 )
+#define GEOSBuffer(g, d, s) GEOSBuffer( (GEOSGeometry*) g, d, s)
+#define GEOSArea(g, a) GEOSArea( (GEOSGeometry*) g, a)
 
+#define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n )
+#define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x )
+#define GEOSCoordSeq_getY(cs,i,y) GEOSCoordSeq_getY( (GEOSCoordSequence *)cs, i, y )
+
+static GEOSGeometry *createGeosCollection( int typeId, QVector<GEOSGeometry*> geoms );
+
+static GEOSGeometry *cloneGeosGeom( const GEOSGeometry *geom )
+{
+  if ( GEOSGeomTypeId( geom ) == GEOS_MULTIPOLYGON )
+  {
+    QVector<GEOSGeometry *> geoms;
+
+    try
+    {
+
+      for ( int i = 0; i < GEOSGetNumGeometries( geom ); ++i )
+        geoms << GEOSGeom_clone(( GEOSGeometry * ) GEOSGetGeometryN(( GEOSGeometry * ) geom, i ) );
+
+      return createGeosCollection( GEOS_MULTIPOLYGON, geoms );
+    }
+    catch ( GEOSException &e )
+    {
+      Q_UNUSED( e );
+      for ( int i = 0; i < geoms.count(); i++ )
+        GEOSGeom_destroy( geoms[i] );
+
+      return 0;
+    }
+  }
+  else
+  {
+    return GEOSGeom_clone(( GEOSGeometry * ) geom );
+  }
+}
+
+#define GEOSGeom_clone(g) cloneGeosGeom(g)
+#endif
+
 int QgsGeometry::refcount = 0;
 
 QgsGeometry::QgsGeometry()



More information about the QGIS-commit mailing list