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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Dec 22 16:07:34 EST 2009


Author: mhugent
Date: 2009-12-22 16:07:32 -0500 (Tue, 22 Dec 2009)
New Revision: 12585

Modified:
   trunk/qgis/src/core/qgsgeometry.cpp
Log:
Test if polygon rings are still inside the outer boundary after reshape and fix a memory leak. Fixes bug #2220

Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp	2009-12-22 20:34:20 UTC (rev 12584)
+++ trunk/qgis/src/core/qgsgeometry.cpp	2009-12-22 21:07:32 UTC (rev 12585)
@@ -531,6 +531,7 @@
   mGeometrySize    = rhs.mGeometrySize;
 
   // deep-copy the GEOS Geometry if appropriate
+  GEOSGeom_destroy( mGeos );
   mGeos = rhs.mGeos ? GEOSGeom_clone( rhs.mGeos ) : 0;
 
   mDirtyGeos = rhs.mDirtyGeos;
@@ -5145,22 +5146,49 @@
     newOuterRing = GEOSGeom_clone( outerRing );
   }
 
-  GEOSGeometry** newInnerRings = new GEOSGeometry*[nRings];
-  for ( int i = 0; i < nRings; ++i )
+  //check if all the rings are still inside the outer boundary
+  QList<GEOSGeometry*> ringList;
+  if ( nRings > 0 )
   {
-    if ( lastIntersectingRing == i )
+    GEOSGeometry* outerRingPoly = GEOSGeom_createPolygon( GEOSGeom_clone( newOuterRing ), 0, 0 );
+    if ( outerRingPoly )
     {
-      newInnerRings[i] = newRing;
+      GEOSGeometry* currentRing = 0;
+      for ( int i = 0; i < nRings; ++i )
+      {
+        if ( lastIntersectingRing == i )
+        {
+          currentRing = newRing;
+        }
+        else
+        {
+          currentRing = GEOSGeom_clone( innerRings[i] );
+        }
+
+        //possibly a ring is no longer contained in the result polygon after reshape
+        if ( GEOSContains( outerRingPoly, currentRing ) == 1 )
+        {
+          ringList.push_back( currentRing );
+        }
+        else
+        {
+          GEOSGeom_destroy( currentRing );
+        }
+      }
     }
-    else
-    {
-      newInnerRings[i] = GEOSGeom_clone( innerRings[i] );
-    }
+    GEOSGeom_destroy( outerRingPoly );
   }
 
+  GEOSGeometry** newInnerRings = new GEOSGeometry*[ringList.size()];
+  QList<GEOSGeometry*>::const_iterator it = ringList.constBegin();
+  for ( int i = 0; i < ringList.size(); ++i )
+  {
+    newInnerRings[i] = ringList.at( i );
+  }
+
   delete [] innerRings;
 
-  GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon( newOuterRing, newInnerRings, nRings );
+  GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon( newOuterRing, newInnerRings, ringList.size() );
   delete[] newInnerRings;
   if ( !reshapedPolygon )
   {



More information about the QGIS-commit mailing list