@@ -222,6 +222,9 @@ bool QgsMapToPixelSimplifier::simplifyWkbGeometry(
222
222
double * ptr = ( double * )targetWkb;
223
223
map2pixelTol *= map2pixelTol; // -> Use mappixelTol for 'LengthSquare' calculations.
224
224
225
+ bool isaUngenerizableSegment;
226
+ bool hasUngenerizableSegments = false ; // -> To avoid replace the simplified geometry by its BBOX when there are 'long' segments.
227
+
225
228
// Check whether the LinearRing is really closed.
226
229
if ( isaLinearRing )
227
230
{
@@ -246,22 +249,29 @@ bool QgsMapToPixelSimplifier::simplifyWkbGeometry(
246
249
memcpy ( &x, sourceWkb, sizeof ( double ) ); sourceWkb += sizeOfDoubleX;
247
250
memcpy ( &y, sourceWkb, sizeof ( double ) ); sourceWkb += sizeOfDoubleY;
248
251
252
+ isaUngenerizableSegment = false ;
253
+
249
254
if ( i == 0 ||
250
255
!isGeneralizable ||
251
- calculateLengthSquared2D ( x, y, lastX, lastY ) > map2pixelTol ||
256
+ ( isaUngenerizableSegment = ( calculateLengthSquared2D ( x, y, lastX, lastY ) > map2pixelTol ) ) ||
252
257
( !isaLinearRing && ( i == 1 || i >= numPoints - 2 ) ) )
253
258
{
254
259
memcpy ( ptr, &x, sizeof ( double ) ); lastX = x; ptr++;
255
260
memcpy ( ptr, &y, sizeof ( double ) ); lastY = y; ptr++;
256
261
numTargetPoints++;
262
+
263
+ if ( isaUngenerizableSegment && !hasUngenerizableSegments )
264
+ {
265
+ hasUngenerizableSegments = true ;
266
+ }
257
267
}
258
268
259
269
r.combineExtentWith ( x, y );
260
270
}
261
271
targetWkb = wkb2 + 4 ;
262
272
263
273
// Fix the topology of the geometry
264
- if ( numTargetPoints <= ( isaLinearRing ? 2 : 1 ) )
274
+ if ( numTargetPoints <= ( isaLinearRing ? 2 : 1 ) && !hasUngenerizableSegments )
265
275
{
266
276
unsigned char * targetTempWkb = targetWkb;
267
277
int targetWkbTempSize = targetWkbSize;
0 commit comments