Skip to content
Permalink
Browse files
Use more accurate tolerances for some geometry modification methods i…
…f geom values in degrees

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13292 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 10, 2010
1 parent 191f70a commit b9db8ed
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
@@ -5441,7 +5441,12 @@ 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;
}
GEOSGeometry* bufferGeom = GEOSBuffer( line2, bufferDistance, DEFAULT_QUADRANT_SEGMENTS );
if ( !bufferGeom )
{
@@ -5476,6 +5481,10 @@ int QgsGeometry::pointContainedInLine( const GEOSGeometry* point, const GEOSGeom
}

double bufferDistance = 0.000001;
if ( geomInDegrees( line ) )
{
bufferDistance = 0.00000001;
}
GEOSGeometry* lineBuffer = GEOSBuffer( line, bufferDistance, 8 );
if ( !lineBuffer )
{
@@ -5492,6 +5501,50 @@ int QgsGeometry::pointContainedInLine( const GEOSGeometry* point, const GEOSGeom
return contained;
}

bool QgsGeometry::geomInDegrees( const GEOSGeometry* geom )
{
GEOSGeometry* bbox = GEOSEnvelope( geom );
if ( !bbox )
{
return false;
}

const GEOSGeometry* bBoxRing = GEOSGetExteriorRing( bbox );
if ( !bBoxRing )
{
return false;
}
const GEOSCoordSequence* bBoxCoordSeq = GEOSGeom_getCoordSeq( bBoxRing );

if ( !bBoxCoordSeq )
{
return false;
}

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

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

return true;
}

int QgsGeometry::numberOfGeometries( GEOSGeometry* g ) const
{
if ( !g )
@@ -505,6 +505,9 @@ 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 );

/**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 b9db8ed

Please sign in to comment.