Skip to content

Commit f9c0682

Browse files
author
mhugent
committedDec 22, 2009
Test if polygon rings are still inside the outer boundary after reshape and fix a memory leak. Fixes bug #2220
git-svn-id: http://svn.osgeo.org/qgis/trunk@12585 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a468957 commit f9c0682

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed
 

‎src/core/qgsgeometry.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ QgsGeometry & QgsGeometry::operator=( QgsGeometry const & rhs )
531531
mGeometrySize = rhs.mGeometrySize;
532532

533533
// deep-copy the GEOS Geometry if appropriate
534+
GEOSGeom_destroy( mGeos );
534535
mGeos = rhs.mGeos ? GEOSGeom_clone( rhs.mGeos ) : 0;
535536

536537
mDirtyGeos = rhs.mDirtyGeos;
@@ -5145,22 +5146,49 @@ GEOSGeometry* QgsGeometry::reshapePolygon( const GEOSGeometry* polygon, const GE
51455146
newOuterRing = GEOSGeom_clone( outerRing );
51465147
}
51475148

5148-
GEOSGeometry** newInnerRings = new GEOSGeometry*[nRings];
5149-
for ( int i = 0; i < nRings; ++i )
5149+
//check if all the rings are still inside the outer boundary
5150+
QList<GEOSGeometry*> ringList;
5151+
if ( nRings > 0 )
51505152
{
5151-
if ( lastIntersectingRing == i )
5152-
{
5153-
newInnerRings[i] = newRing;
5154-
}
5155-
else
5153+
GEOSGeometry* outerRingPoly = GEOSGeom_createPolygon( GEOSGeom_clone( newOuterRing ), 0, 0 );
5154+
if ( outerRingPoly )
51565155
{
5157-
newInnerRings[i] = GEOSGeom_clone( innerRings[i] );
5156+
GEOSGeometry* currentRing = 0;
5157+
for ( int i = 0; i < nRings; ++i )
5158+
{
5159+
if ( lastIntersectingRing == i )
5160+
{
5161+
currentRing = newRing;
5162+
}
5163+
else
5164+
{
5165+
currentRing = GEOSGeom_clone( innerRings[i] );
5166+
}
5167+
5168+
//possibly a ring is no longer contained in the result polygon after reshape
5169+
if ( GEOSContains( outerRingPoly, currentRing ) == 1 )
5170+
{
5171+
ringList.push_back( currentRing );
5172+
}
5173+
else
5174+
{
5175+
GEOSGeom_destroy( currentRing );
5176+
}
5177+
}
51585178
}
5179+
GEOSGeom_destroy( outerRingPoly );
5180+
}
5181+
5182+
GEOSGeometry** newInnerRings = new GEOSGeometry*[ringList.size()];
5183+
QList<GEOSGeometry*>::const_iterator it = ringList.constBegin();
5184+
for ( int i = 0; i < ringList.size(); ++i )
5185+
{
5186+
newInnerRings[i] = ringList.at( i );
51595187
}
51605188

51615189
delete [] innerRings;
51625190

5163-
GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon( newOuterRing, newInnerRings, nRings );
5191+
GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon( newOuterRing, newInnerRings, ringList.size() );
51645192
delete[] newInnerRings;
51655193
if ( !reshapedPolygon )
51665194
{

0 commit comments

Comments
 (0)
Please sign in to comment.