Skip to content

Commit 5305486

Browse files
committedJul 1, 2016
Fix incorrect area calculation for polygon (fix #14675)
(cherry-picked from bf4cf51)
1 parent 221909f commit 5305486

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎src/core/qgsdistancearea.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,8 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPoint>& points ) cons
931931
dx = x2 - x1;
932932
area += dx * ( m_Qp - getQ( y2 ) );
933933

934-
if (( dy = y2 - y1 ) != 0.0 )
934+
dy = y2 - y1;
935+
if ( !qgsDoubleNear( dy, 0.0 ) )
935936
area += dx * getQ( y2 ) - ( dx / dy ) * ( Qbar2 - Qbar1 );
936937
}
937938
if (( area *= m_AE ) < 0.0 )

‎tests/src/core/testqgsdistancearea.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class TestQgsDistanceArea: public QObject
4343
void measureUnits();
4444
void measureAreaAndUnits();
4545
void emptyPolygon();
46+
void regression14675();
4647

4748
};
4849

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

360+
void TestQgsDistanceArea::regression14675()
361+
{
362+
//test regression #14675
363+
QgsDistanceArea calc;
364+
calc.setEllipsoidalMode( true );
365+
calc.setEllipsoid( "GRS80" );
366+
calc.setSourceCrs( 145L );
367+
QgsGeometry geom( QgsGeometryFactory::geomFromWkt( "Polygon ((917593.5791854317067191 6833700.00807378999888897, 917596.43389983859378844 6833700.67099479306489229, 917599.53056440979707986 6833700.78673478215932846, 917593.5791854317067191 6833700.00807378999888897))" ) );
368+
QVERIFY( qgsDoubleNear( calc.measureArea( &geom ), 0.83301, 0.0001 ) );
369+
}
370+
359371
QTEST_MAIN( TestQgsDistanceArea )
360372
#include "testqgsdistancearea.moc"
361373

0 commit comments

Comments
 (0)
Please sign in to comment.