[QGIS Commit] r13292 - trunk/qgis/src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Apr 10 05:16:41 EDT 2010
Author: mhugent
Date: 2010-04-10 05:16:41 -0400 (Sat, 10 Apr 2010)
New Revision: 13292
Modified:
trunk/qgis/src/core/qgsgeometry.cpp
trunk/qgis/src/core/qgsgeometry.h
Log:
Use more accurate tolerances for some geometry modification methods if geom values in degrees
Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp 2010-04-09 07:42:30 UTC (rev 13291)
+++ trunk/qgis/src/core/qgsgeometry.cpp 2010-04-10 09:16:41 UTC (rev 13292)
@@ -5441,7 +5441,12 @@
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 @@
}
double bufferDistance = 0.000001;
+ if ( geomInDegrees( line ) )
+ {
+ bufferDistance = 0.00000001;
+ }
GEOSGeometry* lineBuffer = GEOSBuffer( line, bufferDistance, 8 );
if ( !lineBuffer )
{
@@ -5492,6 +5501,50 @@
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 )
Modified: trunk/qgis/src/core/qgsgeometry.h
===================================================================
--- trunk/qgis/src/core/qgsgeometry.h 2010-04-09 07:42:30 UTC (rev 13291)
+++ trunk/qgis/src/core/qgsgeometry.h 2010-04-10 09:16:41 UTC (rev 13292)
@@ -505,6 +505,9 @@
@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;
More information about the QGIS-commit
mailing list