mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
Port grass followup to area calculation fix
https://trac.osgeo.org/grass/changeset/71259 refs discussion at https://trac.osgeo.org/grass/ticket/3369
This commit is contained in:
parent
7cbf9df21a
commit
773b2e7f9e
@ -674,17 +674,18 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPointXY> &points ) co
|
||||
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 ( !willUseEllipsoid() )
|
||||
@ -732,7 +733,7 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPointXY> &points ) co
|
||||
* (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 );
|
||||
|
||||
@ -377,7 +377,7 @@ void TestQgsDistanceArea::regression14675()
|
||||
calc.setSourceCrs( QgsCoordinateReferenceSystem::fromSrsId( 145L ) );
|
||||
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( QStringLiteral( "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()
|
||||
@ -387,7 +387,7 @@ void TestQgsDistanceArea::regression16820()
|
||||
calc.setSourceCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:32634" ) ) );
|
||||
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))" ) ) );
|
||||
//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.02 );
|
||||
QGSCOMPARENEAR( calc.measureArea( geom ), 43.3280029296875, 0.2 );
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsDistanceArea )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user