Skip to content
Permalink
Browse files

Fix ellipsoidal area calculation

  • Loading branch information
nyalldawson committed Oct 2, 2018
1 parent 36d33ee commit 297dbe0786d30b7b05462c8dac49b51f13175a19
Showing with 7 additions and 7 deletions.
  1. +1 −1 src/core/qgsdistancearea.cpp
  2. +6 −6 tests/src/core/testqgsdistancearea.cpp
@@ -645,7 +645,7 @@ void QgsDistanceArea::computeAreaInit()
}

double a2 = ( mSemiMajor * mSemiMajor );
double e2 = 1 - ( a2 / ( mSemiMinor * mSemiMinor ) );
double e2 = 1 - ( ( mSemiMinor * mSemiMinor ) / a2 );
double e4, e6;

m_TwoPI = M_PI + M_PI;
@@ -239,15 +239,15 @@ void TestQgsDistanceArea::collections()
//collection of polygons
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() );
result = myDa.measureArea( polys );
QGSCOMPARENEAR( result, 670434859475LL, 1 );
QGSCOMPARENEAR( result, 663136985074LL, 1 );
result = myDa.measureLength( polys );
QGSCOMPARENEAR( result, 0, 4 * std::numeric_limits<double>::epsilon() );

//mixed collection
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() );
//measure area specifically
result = myDa.measureArea( mixed );
QGSCOMPARENEAR( result, 670434859475LL, 1 );
QGSCOMPARENEAR( result, 663136985075LL, 1 );
//measure length
result = myDa.measureLength( mixed );
QGSCOMPARENEAR( result, 12006159, 1 );
@@ -312,12 +312,12 @@ void TestQgsDistanceArea::measureAreaAndUnits()
units = da.areaUnits();
QgsDebugMsg( QString( "measured %1 in %2" ).arg( area ).arg( QgsUnitTypes::toString( units ) ) );
// should always be in Meters Squared
QGSCOMPARENEAR( area, 37416879192.9, 0.1 );
QGSCOMPARENEAR( area, 36918093794.1, 0.1 );
QCOMPARE( units, QgsUnitTypes::AreaSquareMeters );

// test converting the resultant area
area = da.convertAreaMeasurement( area, QgsUnitTypes::AreaSquareMiles );
QGSCOMPARENEAR( area, 14446.7378, 0.001 );
QGSCOMPARENEAR( area, 14254.155703, 0.001 );

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

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

void TestQgsDistanceArea::emptyPolygon()

0 comments on commit 297dbe0

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