Skip to content

Commit 297dbe0

Browse files
committed
Fix ellipsoidal area calculation
1 parent 36d33ee commit 297dbe0

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/core/qgsdistancearea.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ void QgsDistanceArea::computeAreaInit()
645645
}
646646

647647
double a2 = ( mSemiMajor * mSemiMajor );
648-
double e2 = 1 - ( a2 / ( mSemiMinor * mSemiMinor ) );
648+
double e2 = 1 - ( ( mSemiMinor * mSemiMinor ) / a2 );
649649
double e4, e6;
650650

651651
m_TwoPI = M_PI + M_PI;

tests/src/core/testqgsdistancearea.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ void TestQgsDistanceArea::collections()
239239
//collection of polygons
240240
QgsGeometry polys( QgsGeometryFactory::geomFromWkt( QStringLiteral( "GeometryCollection( Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) ).release() );
241241
result = myDa.measureArea( polys );
242-
QGSCOMPARENEAR( result, 670434859475LL, 1 );
242+
QGSCOMPARENEAR( result, 663136985074LL, 1 );
243243
result = myDa.measureLength( polys );
244244
QGSCOMPARENEAR( result, 0, 4 * std::numeric_limits<double>::epsilon() );
245245

246246
//mixed collection
247247
QgsGeometry mixed( QgsGeometryFactory::geomFromWkt( QStringLiteral( "GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70), Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) ).release() );
248248
//measure area specifically
249249
result = myDa.measureArea( mixed );
250-
QGSCOMPARENEAR( result, 670434859475LL, 1 );
250+
QGSCOMPARENEAR( result, 663136985075LL, 1 );
251251
//measure length
252252
result = myDa.measureLength( mixed );
253253
QGSCOMPARENEAR( result, 12006159, 1 );
@@ -312,12 +312,12 @@ void TestQgsDistanceArea::measureAreaAndUnits()
312312
units = da.areaUnits();
313313
QgsDebugMsg( QString( "measured %1 in %2" ).arg( area ).arg( QgsUnitTypes::toString( units ) ) );
314314
// should always be in Meters Squared
315-
QGSCOMPARENEAR( area, 37416879192.9, 0.1 );
315+
QGSCOMPARENEAR( area, 36918093794.1, 0.1 );
316316
QCOMPARE( units, QgsUnitTypes::AreaSquareMeters );
317317

318318
// test converting the resultant area
319319
area = da.convertAreaMeasurement( area, QgsUnitTypes::AreaSquareMiles );
320-
QGSCOMPARENEAR( area, 14446.7378, 0.001 );
320+
QGSCOMPARENEAR( area, 14254.155703, 0.001 );
321321

322322
// now try with a source CRS which is in feet
323323
ring.clear();
@@ -350,13 +350,13 @@ void TestQgsDistanceArea::measureAreaAndUnits()
350350
area = da.measureArea( polygon );
351351
units = da.areaUnits();
352352
QgsDebugMsg( QString( "measured %1 in %2" ).arg( area ).arg( QgsUnitTypes::toString( units ) ) );
353-
QGSCOMPARENEAR( area, 184149.37, 1.0 );
353+
QGSCOMPARENEAR( area, 185818.590966, 1.0 );
354354
QCOMPARE( units, QgsUnitTypes::AreaSquareMeters );
355355

356356
// test converting the resultant area
357357
area = da.convertAreaMeasurement( area, QgsUnitTypes::AreaSquareYards );
358358
QgsDebugMsg( QString( "measured %1 in sq yrds" ).arg( area ) );
359-
QGSCOMPARENEAR( area, 220240.8172549, 0.3 );
359+
QGSCOMPARENEAR( area, 222237.185213, 0.3 );
360360
}
361361

362362
void TestQgsDistanceArea::emptyPolygon()

0 commit comments

Comments
 (0)