Skip to content
Permalink
Browse files

#9655: fix invalid simplified geometries

  • Loading branch information
ahuarte47 committed Feb 26, 2014
1 parent bcbf9dd commit 07756756a03d718c0ce18e19b237235e69fa1f2f
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/core/qgsmaptopixelgeometrysimplifier.cpp
@@ -147,6 +147,11 @@ bool QgsMapToPixelSimplifier::simplifyWkbGeometry( int simplifyFlags, QGis::WkbT
bool hasZValue = QGis::wkbDimensions( wkbType ) == 3;
bool result = false;

// Save initial WKB settings to use when the simplification creates invalid geometries
unsigned char* sourcePrevWkb = sourceWkb;
unsigned char* targetPrevWkb = targetWkb;
size_t targetWkbPrevSize = targetWkbSize;

// Can replace the geometry by its BBOX ?
if (( simplifyFlags & QgsMapToPixelSimplifier::SimplifyEnvelope ) && ( envelope.xMaximum() - envelope.xMinimum() ) < map2pixelTol && ( envelope.yMaximum() - envelope.yMinimum() ) < map2pixelTol )
{
@@ -181,6 +186,11 @@ bool QgsMapToPixelSimplifier::simplifyWkbGeometry( int simplifyFlags, QGis::WkbT
{
double x, y, lastX = 0, lastY = 0;

double xmin = std::numeric_limits<double>::max();
double ymin = std::numeric_limits<double>::max();
double xmax = -std::numeric_limits<double>::max();
double ymax = -std::numeric_limits<double>::max();

int sizeOfDoubleX = sizeof( double );
int sizeOfDoubleY = QGis::wkbDimensions( wkbType ) == 3 /*hasZValue*/ ? 2 * sizeof( double ) : sizeof( double );

@@ -209,10 +219,21 @@ bool QgsMapToPixelSimplifier::simplifyWkbGeometry( int simplifyFlags, QGis::WkbT
memcpy( ptr, &y, sizeof( double ) ); lastY = y; ptr++;
numTargetPoints++;
}
if ( xmin > x ) xmin = x;
if ( ymin > y ) ymin = y;
if ( xmax < x ) xmax = x;
if ( ymax < y ) ymax = y;
}
targetWkb = wkb2 + 4;

// Fix the topology of the geometry
if ( numTargetPoints <= ( isaLinearRing ? 2 : 1 ) )
{
sourceWkb = sourcePrevWkb;
targetWkb = targetPrevWkb;
targetWkbSize = targetWkbPrevSize;
return generalizeWkbGeometry( wkbType, sourceWkb, sourceWkbSize, targetWkb, targetWkbSize, QgsRectangle( xmin, ymin, xmax, ymax ), writeHeader );
}
if ( isaLinearRing )
{
memcpy( &x, targetWkb + 0, sizeof( double ) );

0 comments on commit 0775675

Please sign in to comment.
You can’t perform that action at this time.