Skip to content

Commit 773b2e7

Browse files
committed
Port grass followup to area calculation fix
https://trac.osgeo.org/grass/changeset/71259 refs discussion at https://trac.osgeo.org/grass/ticket/3369
1 parent 7cbf9df commit 773b2e7

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/core/qgsdistancearea.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -674,17 +674,18 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPointXY> &points ) co
674674
return 0;
675675
}
676676

677+
// IMPORTANT
678+
// don't change anything here without reporting the changes to upstream (GRASS)
679+
// let's all be good opensource citizens and share the improvements!
680+
677681
double x1, y1, x2, y2, dx, dy;
678682
double Qbar1, Qbar2;
679683
double area;
680684

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

689690
QgsDebugMsgLevel( "Ellipsoid: " + mEllipsoid, 3 );
690691
if ( !willUseEllipsoid() )
@@ -732,7 +733,7 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPointXY> &points ) co
732733
* (Qbar2 - Qbar1) / dy should approach Q((y1 + y2) / 2)
733734
* Metz 2017
734735
*/
735-
area += dx * ( m_Qp - getQ( y2 ) );
736+
area += dx * ( m_Qp - getQ( ( y1 + y2 ) / 2.0 ) );
736737

737738
/* original:
738739
* area += dx * getQ( y2 ) - ( dx / dy ) * ( Qbar2 - Qbar1 );

tests/src/core/testqgsdistancearea.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ void TestQgsDistanceArea::regression14675()
377377
calc.setSourceCrs( QgsCoordinateReferenceSystem::fromSrsId( 145L ) );
378378
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( QStringLiteral( "Polygon ((917593.5791854317067191 6833700.00807378999888897, 917596.43389983859378844 6833700.67099479306489229, 917599.53056440979707986 6833700.78673478215932846, 917593.5791854317067191 6833700.00807378999888897))" ) ) );
379379
//lots of tolerance here - the formulas get quite unstable with small areas due to division by very small floats
380-
QGSCOMPARENEAR( calc.measureArea( geom ), 0.83301, 0.02 );
380+
QGSCOMPARENEAR( calc.measureArea( geom ), 0.833010, 0.03 );
381381
}
382382

383383
void TestQgsDistanceArea::regression16820()
@@ -387,7 +387,7 @@ void TestQgsDistanceArea::regression16820()
387387
calc.setSourceCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:32634" ) ) );
388388
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( QStringLiteral( "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))" ) ) );
389389
//lots of tolerance here - the formulas get quite unstable with small areas due to division by very small floats
390-
QGSCOMPARENEAR( calc.measureArea( geom ), 43.183369, 0.02 );
390+
QGSCOMPARENEAR( calc.measureArea( geom ), 43.3280029296875, 0.2 );
391391
}
392392

393393
QGSTEST_MAIN( TestQgsDistanceArea )

0 commit comments

Comments
 (0)