@@ -678,6 +678,14 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPointXY> &points ) co
678
678
double Qbar1, Qbar2;
679
679
double area;
680
680
681
+ /* 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
+ */
687
+ const double thresh = 0.7e-7 ;
688
+
681
689
QgsDebugMsgLevel ( " Ellipsoid: " + mEllipsoid , 3 );
682
690
if ( !willUseEllipsoid () )
683
691
{
@@ -708,11 +716,28 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPointXY> &points ) co
708
716
x1 += m_TwoPI;
709
717
710
718
dx = x2 - x1;
711
- area += dx * ( m_Qp - getQ ( y2 ) );
712
-
713
719
dy = y2 - y1 ;
714
- if ( !qgsDoubleNear ( dy, 0.0 ) )
715
- area += dx * getQ ( y2 ) - ( dx / dy ) * ( Qbar2 - Qbar1 );
720
+ if ( qAbs ( dy ) > thresh )
721
+ {
722
+ /* account for different latitudes y1, y2 */
723
+ area += dx * ( m_Qp - ( Qbar2 - Qbar1 ) / dy );
724
+ }
725
+ else
726
+ {
727
+ /* latitudes y1, y2 are (nearly) identical */
728
+
729
+ /* if y2 becomes similar to y1, i.e. y2 -> y1
730
+ * Qbar2 - Qbar1 -> 0 and dy -> 0
731
+ * (Qbar2 - Qbar1) / dy -> ?
732
+ * (Qbar2 - Qbar1) / dy should approach Q((y1 + y2) / 2)
733
+ * Metz 2017
734
+ */
735
+ area += dx * ( m_Qp - getQ ( y2 ) );
736
+
737
+ /* original:
738
+ * area += dx * getQ( y2 ) - ( dx / dy ) * ( Qbar2 - Qbar1 );
739
+ */
740
+ }
716
741
}
717
742
if ( ( area *= m_AE ) < 0.0 )
718
743
area = -area;
0 commit comments