Skip to content

Commit

Permalink
Fix incorrect area calculation for polygon (fix #14675)
Browse files Browse the repository at this point in the history
(cherry-picked from bf4cf51)
  • Loading branch information
nyalldawson committed Jul 1, 2016
1 parent 221909f commit 5305486
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/qgsdistancearea.cpp
Expand Up @@ -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 )
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/testqgsdistancearea.cpp
Expand Up @@ -43,6 +43,7 @@ class TestQgsDistanceArea: public QObject
void measureUnits();
void measureAreaAndUnits();
void emptyPolygon();
void regression14675();

};

Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 5305486

Please sign in to comment.