Skip to content

Commit 3286944

Browse files
author
mhugent
committed
Use more accurate tolerances for some geometry modification methods if geom values in degrees
git-svn-id: http://svn.osgeo.org/qgis/trunk@13292 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f930a16 commit 3286944

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/core/qgsgeometry.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -5441,7 +5441,12 @@ int QgsGeometry::lineContainedInLine( const GEOSGeometry* line1, const GEOSGeome
54415441
return -1;
54425442
}
54435443

5444+
54445445
double bufferDistance = 0.00001;
5446+
if ( geomInDegrees( line2 ) ) //use more accurate tolerance for degrees
5447+
{
5448+
bufferDistance = 0.00000001;
5449+
}
54455450
GEOSGeometry* bufferGeom = GEOSBuffer( line2, bufferDistance, DEFAULT_QUADRANT_SEGMENTS );
54465451
if ( !bufferGeom )
54475452
{
@@ -5476,6 +5481,10 @@ int QgsGeometry::pointContainedInLine( const GEOSGeometry* point, const GEOSGeom
54765481
}
54775482

54785483
double bufferDistance = 0.000001;
5484+
if ( geomInDegrees( line ) )
5485+
{
5486+
bufferDistance = 0.00000001;
5487+
}
54795488
GEOSGeometry* lineBuffer = GEOSBuffer( line, bufferDistance, 8 );
54805489
if ( !lineBuffer )
54815490
{
@@ -5492,6 +5501,50 @@ int QgsGeometry::pointContainedInLine( const GEOSGeometry* point, const GEOSGeom
54925501
return contained;
54935502
}
54945503

5504+
bool QgsGeometry::geomInDegrees( const GEOSGeometry* geom )
5505+
{
5506+
GEOSGeometry* bbox = GEOSEnvelope( geom );
5507+
if ( !bbox )
5508+
{
5509+
return false;
5510+
}
5511+
5512+
const GEOSGeometry* bBoxRing = GEOSGetExteriorRing( bbox );
5513+
if ( !bBoxRing )
5514+
{
5515+
return false;
5516+
}
5517+
const GEOSCoordSequence* bBoxCoordSeq = GEOSGeom_getCoordSeq( bBoxRing );
5518+
5519+
if ( !bBoxCoordSeq )
5520+
{
5521+
return false;
5522+
}
5523+
5524+
unsigned int nCoords = 0;
5525+
if ( !GEOSCoordSeq_getSize( bBoxCoordSeq, &nCoords ) )
5526+
{
5527+
return false;
5528+
}
5529+
5530+
double x, y;
5531+
for ( int i = 0; i < ( nCoords - 1 ); ++i )
5532+
{
5533+
GEOSCoordSeq_getX( bBoxCoordSeq, i, &x );
5534+
if ( x > 180 || x < -180 )
5535+
{
5536+
return false;
5537+
}
5538+
GEOSCoordSeq_getY( bBoxCoordSeq, i, &y );
5539+
if ( y > 90 || y < -90 )
5540+
{
5541+
return false;
5542+
}
5543+
}
5544+
5545+
return true;
5546+
}
5547+
54955548
int QgsGeometry::numberOfGeometries( GEOSGeometry* g ) const
54965549
{
54975550
if ( !g )

src/core/qgsgeometry.h

+3
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ class CORE_EXPORT QgsGeometry
505505
@return 0 not contained, 1 if contained, <0 in case of error*/
506506
static int pointContainedInLine( const GEOSGeometry* point, const GEOSGeometry* line );
507507

508+
/**Tests if geom bounding rect is within -180 <= x <= 180, -90 <= y <= 90. Other methods may use more accurate tolerances if this is true*/
509+
static bool geomInDegrees( const GEOSGeometry* geom );
510+
508511
/**Returns number of single geometry in a geos geometry. Is save for geos 2 and 3*/
509512
int numberOfGeometries( GEOSGeometry* g ) const;
510513

0 commit comments

Comments
 (0)