Skip to content
Permalink
Browse files

Test if polygon rings are still inside the outer boundary after resha…

…pe and fix a memory leak. Fixes bug #2220

git-svn-id: http://svn.osgeo.org/qgis/trunk@12585 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Dec 22, 2009
1 parent a468957 commit f9c0682aba43b6ea6b955acd46e77b829f735dde
Showing with 37 additions and 9 deletions.
  1. +37 −9 src/core/qgsgeometry.cpp
@@ -531,6 +531,7 @@ QgsGeometry & QgsGeometry::operator=( QgsGeometry const & rhs )
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 @@ GEOSGeometry* QgsGeometry::reshapePolygon( const GEOSGeometry* polygon, const GE
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 )
{
newInnerRings[i] = newRing;
}
else
GEOSGeometry* outerRingPoly = GEOSGeom_createPolygon( GEOSGeom_clone( newOuterRing ), 0, 0 );
if ( outerRingPoly )
{
newInnerRings[i] = GEOSGeom_clone( innerRings[i] );
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 );
}
}
}
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 )
{

0 comments on commit f9c0682

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