Skip to content
Permalink
Browse files

Fix incorrect area calculation for polygon (fix #14675)

(cherry-picked from bf4cf51)
  • Loading branch information
nyalldawson committed Jul 1, 2016
1 parent 221909f commit 5305486ec87f0bd11df99e1512c1f5ed6ec13ece
Showing with 14 additions and 1 deletion.
  1. +2 −1 src/core/qgsdistancearea.cpp
  2. +12 −0 tests/src/core/testqgsdistancearea.cpp
@@ -931,7 +931,8 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPoint>& points ) cons
dx = x2 - x1;
area += dx * ( m_Qp - getQ( y2 ) );

if (( dy = y2 - y1 ) != 0.0 )
dy = y2 - y1;
if ( !qgsDoubleNear( dy, 0.0 ) )
area += dx * getQ( y2 ) - ( dx / dy ) * ( Qbar2 - Qbar1 );
}
if (( area *= m_AE ) < 0.0 )
@@ -43,6 +43,7 @@ class TestQgsDistanceArea: public QObject
void measureUnits();
void measureAreaAndUnits();
void emptyPolygon();
void regression14675();

};

@@ -356,6 +357,17 @@ void TestQgsDistanceArea::emptyPolygon()
da.measurePolygon( QList< QgsPoint >() );
}

void TestQgsDistanceArea::regression14675()
{
//test regression #14675
QgsDistanceArea calc;
calc.setEllipsoidalMode( true );
calc.setEllipsoid( "GRS80" );
calc.setSourceCrs( 145L );
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( "Polygon ((917593.5791854317067191 6833700.00807378999888897, 917596.43389983859378844 6833700.67099479306489229, 917599.53056440979707986 6833700.78673478215932846, 917593.5791854317067191 6833700.00807378999888897))" ) );
QVERIFY( qgsDoubleNear( calc.measureArea( &geom ), 0.83301, 0.0001 ) );
}

QTEST_MAIN( TestQgsDistanceArea )
#include "testqgsdistancearea.moc"

0 comments on commit 5305486

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