Skip to content
Permalink
Browse files
adapt tolerance to coordinate range when reshaping (fixes #9802)
  • Loading branch information
jef-n committed Jun 12, 2014
1 parent d8a0361 commit d1e3dbc86ed892b6a5b1f41056adba0aef9e108b
Showing with 22 additions and 22 deletions.
  1. +20 −20 src/core/qgsgeometry.cpp
  2. +2 −2 src/core/qgsgeometry.h
@@ -5187,9 +5187,7 @@ int QgsGeometry::lineContainedInLine( const GEOSGeometry* line1, const GEOSGeome
return -1;
}

double bufferDistance = 0.00001;
if ( geomInDegrees( line2 ) ) //use more accurate tolerance for degrees
bufferDistance = 0.00000001;
double bufferDistance = pow( 1.0L, geomDigits( line2 )-11 );

GEOSGeometry* bufferGeom = GEOSBuffer( line2, bufferDistance, DEFAULT_QUADRANT_SEGMENTS );
if ( !bufferGeom )
@@ -5219,9 +5217,7 @@ int QgsGeometry::pointContainedInLine( const GEOSGeometry* point, const GEOSGeom
if ( !point || !line )
return -1;

double bufferDistance = 0.000001;
if ( geomInDegrees( line ) )
bufferDistance = 0.00000001;
double bufferDistance = pow( 1.0L, geomDigits( line )-11 );

GEOSGeometry* lineBuffer = GEOSBuffer( line, bufferDistance, 8 );
if ( !lineBuffer )
@@ -5235,39 +5231,43 @@ int QgsGeometry::pointContainedInLine( const GEOSGeometry* point, const GEOSGeom
return contained;
}

bool QgsGeometry::geomInDegrees( const GEOSGeometry* geom )
int QgsGeometry::geomDigits( const GEOSGeometry* geom )
{
GEOSGeometry* bbox = GEOSEnvelope( geom );
if ( !bbox )
return false;
return -1;

const GEOSGeometry* bBoxRing = GEOSGetExteriorRing( bbox );
if ( !bBoxRing )
return false;
return -1;

const GEOSCoordSequence* bBoxCoordSeq = GEOSGeom_getCoordSeq( bBoxRing );

if ( !bBoxCoordSeq )
return false;
return -1;

unsigned int nCoords = 0;
if ( !GEOSCoordSeq_getSize( bBoxCoordSeq, &nCoords ) )
return false;
return -1;

double x, y;
for ( unsigned int i = 0; i < ( nCoords - 1 ); ++i )
int maxDigits = -1;
for ( unsigned int i = 0; i < nCoords - 1; ++i )
{
GEOSCoordSeq_getX( bBoxCoordSeq, i, &x );
if ( x > 180 || x < -180 )
return false;
double t;
GEOSCoordSeq_getX( bBoxCoordSeq, i, &t );

GEOSCoordSeq_getY( bBoxCoordSeq, i, &y );
if ( y > 90 || y < -90 )
return false;
int digits;
digits = ceil( log10( fabs( t ) ) );
if( digits > maxDigits )
maxDigits = digits;

GEOSCoordSeq_getY( bBoxCoordSeq, i, &t );
digits = ceil( log10( fabs( t ) ) );
if( digits > maxDigits )
maxDigits = digits;
}

return true;
return maxDigits;
}

int QgsGeometry::numberOfGeometries( GEOSGeometry* g ) const
@@ -600,8 +600,8 @@ class CORE_EXPORT QgsGeometry
@return 0 not contained, 1 if contained, <0 in case of error*/
static int pointContainedInLine( const GEOSGeometry* point, const GEOSGeometry* line );

/**Tests if geom bounding rect is within -180 <= x <= 180, -90 <= y <= 90. Other methods may use more accurate tolerances if this is true*/
static bool geomInDegrees( const GEOSGeometry* geom );
/** Determines the maximum number of digits before the dot */
static int geomDigits( const GEOSGeometry* geom );

/**Returns number of single geometry in a geos geometry. Is save for geos 2 and 3*/
int numberOfGeometries( GEOSGeometry* g ) const;

0 comments on commit d1e3dbc

Please sign in to comment.