Skip to content

Commit

Permalink
Use more accurate tolerances for some geometry modification methods i…
Browse files Browse the repository at this point in the history
…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.
53 changes: 53 additions & 0 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b9db8ed

Please sign in to comment.