Skip to content
Permalink
Browse files

Port grass followup to area calculation fix

  • Loading branch information
nyalldawson committed Jul 14, 2017
1 parent bd1f9bf commit cbe7e3fef2a22ec346a54a83770784f397dbd298
Showing with 9 additions and 8 deletions.
  1. +7 −6 src/core/qgsdistancearea.cpp
  2. +2 −2 tests/src/core/testqgsdistancearea.cpp
@@ -893,17 +893,18 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPoint>& points ) cons
return 0;
}

// IMPORTANT
// don't change anything here without reporting the changes to upstream (GRASS)
// let's all be good opensource citizens and share the improvements!

double x1, y1, x2, y2, dx, dy;
double Qbar1, Qbar2;
double area;

/* GRASS comment: threshold for dy, should be between 1e-4 and 1e-7
* QGIS note: while the grass comment states that thres should be between 1e-4->1e-7,
* a value of 1e-7 caused TestQgsDistanceArea::regression14675() to regress
* The maximum threshold possible which permits regression14675() to pass
* was found to be ~0.7e-7.
* See relevant discussion at https://trac.osgeo.org/grass/ticket/3369
*/
const double thresh = 0.7e-7;
const double thresh = 1e-6;

QgsDebugMsgLevel( "Ellipsoid: " + mEllipsoid, 3 );
if (( ! mEllipsoidalMode ) || ( mEllipsoid == GEO_NONE ) )
@@ -951,7 +952,7 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPoint>& points ) cons
* (Qbar2 - Qbar1) / dy should approach Q((y1 + y2) / 2)
* Metz 2017
*/
area += dx * ( m_Qp - getQ( y2 ) );
area += dx * ( m_Qp - getQ( ( y1 + y2 ) / 2.0 ) );

/* original:
* area += dx * getQ( y2 ) - ( dx / dy ) * ( Qbar2 - Qbar1 );
@@ -368,7 +368,7 @@ void TestQgsDistanceArea::regression14675()
calc.setSourceCrs( 145L );
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( "Polygon ((917593.5791854317067191 6833700.00807378999888897, 917596.43389983859378844 6833700.67099479306489229, 917599.53056440979707986 6833700.78673478215932846, 917593.5791854317067191 6833700.00807378999888897))" ) );
//lots of tolerance here - the formulas get quite unstable with small areas due to division by very small floats
QGSCOMPARENEAR( calc.measureArea( &geom ), 0.83301, 0.02 );
QGSCOMPARENEAR( calc.measureArea( &geom ), 0.833010, 0.03 );
}

void TestQgsDistanceArea::regression16820()
@@ -378,7 +378,7 @@ void TestQgsDistanceArea::regression16820()
calc.setSourceCrs( QgsCoordinateReferenceSystem( "EPSG:32634" ) );
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( "Polygon ((110250.54038314701756462 5084495.57398066483438015, 110243.46975068224128336 5084507.17200060561299324, 110251.23908144699817058 5084506.68309532757848501, 110251.2394439501222223 5084506.68307251576334238, 110250.54048078990308568 5084495.57553235255181789, 110250.54038314701756462 5084495.57398066483438015))" ) );
//lots of tolerance here - the formulas get quite unstable with small areas due to division by very small floats
QGSCOMPARENEAR( calc.measureArea( &geom ), 43.183369, 0.2 );
QGSCOMPARENEAR( calc.measureArea( &geom ), 43.3280029296875, 0.2 );
}

QTEST_MAIN( TestQgsDistanceArea )

0 comments on commit cbe7e3f

Please sign in to comment.
You can’t perform that action at this time.