Skip to content
Permalink
Browse files

Added possibility to set custom ellipsoid

  • Loading branch information
homann committed Sep 3, 2012
1 parent 143300d commit 6154f8eef4a545c79d87bb180992f43589164843
Showing with 27 additions and 0 deletions.
  1. +19 −0 src/core/qgsdistancearea.cpp
  2. +4 −0 src/core/qgsdistancearea.h
  3. +4 −0 tests/src/core/testqgsdistancearea.cpp
@@ -79,6 +79,9 @@ void QgsDistanceArea::_copy( const QgsDistanceArea & origDA )
mSemiMajor = origDA.mSemiMajor;
mSemiMinor = origDA.mSemiMinor;
mInvFlattening = origDA.mInvFlattening;
// Some calculations and trig. Should not be TOO time consuming.
// Alternatively we could copy the temp vars?
computeAreaInit();
mSourceRefSys = origDA.mSourceRefSys;
mCoordTransform = new QgsCoordinateTransform( origDA.mCoordTransform->sourceCrs(), origDA.mCoordTransform->destCRS() );
}
@@ -205,6 +208,22 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
return true;
}

//! Sets ellipsoid by supplied radii
// Inverse flattening is calculated with invf = a/(a-b)
// Also, b = a-(a/invf)
bool QgsDistanceArea::setEllipsoid( double semiMajor, double semiMinor )
{
mEllipsoid = "PARAMETER";
mSemiMajor = semiMajor;
mSemiMinor = semiMinor;
mInvFlattening = mSemiMajor / ( mSemiMajor - mSemiMinor );

computeAreaInit();

return true;
}



double QgsDistanceArea::measure( QgsGeometry* geometry )
{
@@ -71,6 +71,10 @@ class CORE_EXPORT QgsDistanceArea
//! sets ellipsoid by its acronym
bool setEllipsoid( const QString& ellipsoid );

//! Sets ellipsoid by supplied radii
// Inverse flattening is calculated with invf = a/(a-b)
bool setEllipsoid( double semiMajor, double semiMinor );

//! returns ellipsoid's acronym
const QString& ellipsoid() { return mEllipsoid; }

@@ -81,6 +81,10 @@ void TestQgsDistanceArea::basic()
QCOMPARE( resultB, resultC );
delete daC;

// Use parameter setting of ellipsoid radii (from WGS72 )
daA.setEllipsoid( 6378135.0, 6378135.0 - ( 6378135.0 / 298.26 ) );
resultA = daA.measureLine( p1, p2 );
QCOMPARE( resultA, resultB );
};

void TestQgsDistanceArea::test_distances()

0 comments on commit 6154f8e

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