Skip to content
Permalink
Browse files

don't crash when measuring faulty geometry (fixes partially #7991)

  • Loading branch information
jef-n committed Jun 30, 2013
1 parent 608526c commit fe9b8d4672dbad90f7513c1ab771fef7ce3ec533
Showing with 30 additions and 2 deletions.
  1. +20 −2 src/core/qgsdistancearea.cpp
  2. +10 −0 src/core/qgsgeometryvalidator.cpp
@@ -308,6 +308,11 @@ double QgsDistanceArea::measure( QgsGeometry* geometry )
for ( i = 0; i < count; i++ )
{
ptr = measurePolygon( ptr, &res, 0, hasZptr );
if ( !ptr )
{
QgsDebugMsg( "measurePolygon returned 0" );
break;
}
resTotal += res;
}
QgsDebugMsg( "returning " + QString::number( resTotal ) );
@@ -330,7 +335,7 @@ double QgsDistanceArea::measurePerimeter( QgsGeometry* geometry )

const unsigned char* ptr;
unsigned int wkbType;
double res, resTotal = 0;
double res = 0.0, resTotal = 0.0;
int count, i;

memcpy( &wkbType, ( wkb + 1 ), sizeof( wkbType ) );
@@ -361,6 +366,11 @@ double QgsDistanceArea::measurePerimeter( QgsGeometry* geometry )
for ( i = 0; i < count; i++ )
{
ptr = measurePolygon( ptr, 0, &res, hasZptr );
if ( !ptr )
{
QgsDebugMsg( "measurePolygon returned 0" );
break;
}
resTotal += res;
}
QgsDebugMsg( "returning " + QString::number( resTotal ) );
@@ -483,11 +493,20 @@ double QgsDistanceArea::measureLine( const QgsPoint& p1, const QgsPoint& p2 )

const unsigned char* QgsDistanceArea::measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr )
{
if ( !feature )
{
QgsDebugMsg( "no feature to measure" );
return 0;
}

// get number of rings in the polygon
unsigned int numRings = *(( int* )( feature + 1 + sizeof( int ) ) );

if ( numRings == 0 )
{
QgsDebugMsg( "no rings to measure" );
return 0;
}

// Set pointer to the first ring
const unsigned char* ptr = feature + 1 + 2 * sizeof( int );
@@ -571,7 +590,6 @@ const unsigned char* QgsDistanceArea::measurePolygon( const unsigned char* featu

double QgsDistanceArea::measurePolygon( const QList<QgsPoint>& points )
{

try
{
if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) )
@@ -282,8 +282,18 @@ void QgsGeometryValidator::run()

for ( int i = 0; !mStop && i < mp.size(); i++ )
{
if ( mp[i].isEmpty() )
{
emit errorFound( QgsGeometry::Error( QObject::tr( "polygon %1 has no rings" ).arg( i ) ) );
mErrorCount++;
continue;
}

for ( int j = i + 1; !mStop && j < mp.size(); j++ )
{
if ( mp[j].isEmpty() )
continue;

if ( ringInRing( mp[i][0], mp[j][0] ) )
{
emit errorFound( QgsGeometry::Error( QObject::tr( "polygon %1 inside polygon %2" ).arg( i ).arg( j ) ) );

0 comments on commit fe9b8d4

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