Skip to content

Commit

Permalink
Test if polygon rings are still inside the outer boundary after resha…
Browse files Browse the repository at this point in the history
…pe and fix a memory leak. Fixes bug #2220

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12585 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Dec 22, 2009
1 parent fd51d10 commit 4b79f30
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand Down

0 comments on commit 4b79f30

Please sign in to comment.