@@ -531,6 +531,7 @@ QgsGeometry & QgsGeometry::operator=( QgsGeometry const & rhs )
531
531
mGeometrySize = rhs.mGeometrySize ;
532
532
533
533
// deep-copy the GEOS Geometry if appropriate
534
+ GEOSGeom_destroy ( mGeos );
534
535
mGeos = rhs.mGeos ? GEOSGeom_clone ( rhs.mGeos ) : 0 ;
535
536
536
537
mDirtyGeos = rhs.mDirtyGeos ;
@@ -5145,22 +5146,49 @@ GEOSGeometry* QgsGeometry::reshapePolygon( const GEOSGeometry* polygon, const GE
5145
5146
newOuterRing = GEOSGeom_clone ( outerRing );
5146
5147
}
5147
5148
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 )
5150
5152
{
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 )
5156
5155
{
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
+ }
5158
5178
}
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 );
5159
5187
}
5160
5188
5161
5189
delete [] innerRings;
5162
5190
5163
- GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon ( newOuterRing, newInnerRings, nRings );
5191
+ GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon ( newOuterRing, newInnerRings, ringList. size () );
5164
5192
delete[] newInnerRings;
5165
5193
if ( !reshapedPolygon )
5166
5194
{
0 commit comments