@@ -379,18 +379,19 @@ inline static bool generalizeGeometry( QGis::WkbType wkbType, unsigned char* sou
379
379
}
380
380
381
381
// ! Simplify the WKB-geometry using the specified tolerance
382
- inline static bool simplifyWkbGeometry ( QGis::WkbType wkbType, unsigned char * sourceWkb, size_t sourceWkbSize, unsigned char * targetWkb, size_t & targetWkbSize, const QgsRectangle& envelope, float map2pixelTol, bool writeHeader = true , bool isaLinearRing = false )
382
+ inline static bool simplifyWkbGeometry ( const QgsFeatureRequest::Flags& requestFlags, QGis::WkbType wkbType, unsigned char * sourceWkb, size_t sourceWkbSize, unsigned char * targetWkb, size_t & targetWkbSize, const QgsRectangle& envelope, float map2pixelTol, bool writeHeader = true , bool isaLinearRing = false )
383
383
{
384
384
bool canbeGeneralizable = true ;
385
385
bool hasZValue = QGis::wkbDimensions (wkbType)==3 ;
386
386
bool result = false ;
387
387
388
388
// Can replace the geometry by its BBOX ?
389
- if ( (envelope.xMaximum ()-envelope.xMinimum ()) < map2pixelTol && (envelope.yMaximum ()-envelope.yMinimum ()) < map2pixelTol )
389
+ if ( ( requestFlags & QgsFeatureRequest::SimplifyEnvelope ) && ( envelope.xMaximum ()-envelope.xMinimum ()) < map2pixelTol && (envelope.yMaximum ()-envelope.yMinimum ()) < map2pixelTol )
390
390
{
391
391
canbeGeneralizable = generalizeGeometry ( wkbType, sourceWkb, sourceWkbSize, targetWkb, targetWkbSize, envelope, writeHeader );
392
392
if (canbeGeneralizable) return true ;
393
393
}
394
+ if (!( requestFlags & QgsFeatureRequest::SimplifyGeometry ) ) canbeGeneralizable = false ;
394
395
395
396
// Write the main header of the geometry
396
397
if ( writeHeader )
@@ -484,7 +485,7 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
484
485
size_t sourceWkbSize_i = 4 + numPoints_i * (hasZValue ? 3 : 2 ) * sizeof (double );
485
486
size_t targetWkbSize_i = 0 ;
486
487
487
- result |= simplifyWkbGeometry ( wkbType, sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope_i, map2pixelTol, false , true );
488
+ result |= simplifyWkbGeometry ( requestFlags, wkbType, sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope_i, map2pixelTol, false , true );
488
489
sourceWkb += sourceWkbSize_i;
489
490
targetWkb += targetWkbSize_i;
490
491
@@ -535,7 +536,7 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
535
536
wkb1 += wkbSize_i;
536
537
}
537
538
}
538
- result |= simplifyWkbGeometry ( QGis::singleType (wkbType), sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope, map2pixelTol, true , false );
539
+ result |= simplifyWkbGeometry ( requestFlags, QGis::singleType (wkbType), sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope, map2pixelTol, true , false );
539
540
sourceWkb += sourceWkbSize_i;
540
541
targetWkb += targetWkbSize_i;
541
542
@@ -573,7 +574,7 @@ bool QgsFeatureRequest::canbeGeneralizedByMapBoundingBox( const QgsRectangle& en
573
574
}
574
575
575
576
// ! Simplify the specified geometry (Removing duplicated points) when is applied the map2pixel context
576
- bool QgsFeatureRequest::simplifyGeometry ( QgsGeometry* geometry, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
577
+ bool QgsFeatureRequest::simplifyGeometry ( const QgsFeatureRequest::Flags& requestFlags, QgsGeometry* geometry, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
577
578
{
578
579
size_t targetWkbSize = 0 ;
579
580
@@ -589,7 +590,7 @@ bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordi
589
590
size_t wkbSize = geometry->wkbSize ( );
590
591
591
592
// Simplify the geometry rewriting temporally its WKB-stream for saving calloc's.
592
- if ( simplifyWkbGeometry ( wkbType, wkb, wkbSize, wkb, targetWkbSize, envelope, map2pixelTol ) )
593
+ if ( simplifyWkbGeometry ( requestFlags, wkbType, wkb, wkbSize, wkb, targetWkbSize, envelope, map2pixelTol ) )
593
594
{
594
595
unsigned char * targetWkb = (unsigned char *)malloc ( targetWkbSize );
595
596
memcpy ( targetWkb, wkb, targetWkbSize );
@@ -600,8 +601,10 @@ bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordi
600
601
}
601
602
602
603
// ! Simplify the specified point stream (Removing duplicated points) when is applied the map2pixel context
603
- bool QgsFeatureRequest::simplifyGeometry ( QGis::GeometryType geometryType, const QgsRectangle& envelope, double * xptr, int xStride, double * yptr, int yStride, int pointCount, int & pointSimplifiedCount, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
604
+ bool QgsFeatureRequest::simplifyGeometry ( const QgsFeatureRequest::Flags& requestFlags, QGis::GeometryType geometryType, const QgsRectangle& envelope, double * xptr, int xStride, double * yptr, int yStride, int pointCount, int & pointSimplifiedCount, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
604
605
{
606
+ bool canbeGeneralizable = ( requestFlags & QgsFeatureRequest::SimplifyGeometry );
607
+
605
608
pointSimplifiedCount = pointCount;
606
609
if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) return false ;
607
610
pointSimplifiedCount = 0 ;
@@ -620,7 +623,7 @@ bool QgsFeatureRequest::simplifyGeometry( QGis::GeometryType geometryType, const
620
623
memcpy ( &x, xsourcePtr, sizeof ( double ) ); xsourcePtr += xStride;
621
624
memcpy ( &y, ysourcePtr, sizeof ( double ) ); ysourcePtr += yStride;
622
625
623
- if ( i==0 || calculateLengthSquared2D (x,y,lastX,lastY)>map2pixelTol )
626
+ if ( i==0 || !canbeGeneralizable || calculateLengthSquared2D (x,y,lastX,lastY)>map2pixelTol )
624
627
{
625
628
memcpy ( xtargetPtr, &x, sizeof ( double ) ); lastX = x; xtargetPtr += xStride;
626
629
memcpy ( ytargetPtr, &y, sizeof ( double ) ); lastY = y; ytargetPtr += yStride;
0 commit comments