Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Port grass followup to area calculation fix
  • Loading branch information
nyalldawson committed Jul 14, 2017
1 parent bd1f9bf commit cbe7e3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/core/qgsdistancearea.cpp
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsdistancearea.cpp
Expand Up @@ -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()
Expand All @@ -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 )
Expand Down

0 comments on commit cbe7e3f

Please sign in to comment.