{{ message }}

# qgis / QGIS

Fix #9951 (perimeter completely wrong with OTF on)

```With OTF on and computation on an ellipsoid, the coordinates
were transformed twice(!) when measuring perimeter.```
wonder-sk committed Jun 10, 2014
1 parent 1d1eed4 commit a19886d2f5d8b4acc3c4aac3cd887619cd81bf9f
Showing with 54 additions and 2 deletions.
1. +5 −0 python/core/qgsdistancearea.sip
2. +44 −2 src/core/qgsdistancearea.cpp
3. +5 −0 src/core/qgsdistancearea.h
 @@ -99,6 +99,11 @@ class QgsDistanceArea double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2, double* course1 = NULL, double* course2 = NULL ); //! uses flat / planimetric / Euclidean distance double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ); //! calculate distance with given coordinates (does not do a transform anymore) double computeDistance( const QList& points ); /** calculates area of polygon on ellipsoid
 @@ -474,7 +474,7 @@ double QgsDistanceArea::measureLine( const QgsPoint &p1, const QgsPoint &p2 ) else { QgsDebugMsgLevel( "Cartesian calculation on canvas coordinates", 4 ); result = sqrt(( p2.x() - p1.x() ) * ( p2.x() - p1.x() ) + ( p2.y() - p1.y() ) * ( p2.y() - p1.y() ) ); result = computeDistanceFlat( p1, p2 ); } } catch ( QgsCsException &cse ) @@ -565,7 +565,7 @@ const unsigned char *QgsDistanceArea::measurePolygon( const unsigned char* featu if ( idx == 0 ) { // exterior ring *perimeter += measureLine( points ); *perimeter += computeDistance( points ); } } } @@ -712,6 +712,48 @@ double QgsDistanceArea::computeDistanceBearing( return s; } double QgsDistanceArea::computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) { return sqrt( ( p2.x() - p1.x() ) * ( p2.x() - p1.x() ) + ( p2.y() - p1.y() ) * ( p2.y() - p1.y() ) ); } double QgsDistanceArea::computeDistance( const QList& points ) { if ( points.size() < 2 ) return 0; double total = 0; QgsPoint p1, p2; try { p1 = points; for ( QList::const_iterator i = points.begin(); i != points.end(); ++i ) { p2 = *i; if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) { total += computeDistanceBearing( p1, p2 ); } else { total += computeDistanceFlat( p1, p2 ); } p1 = p2; } return total; } catch ( QgsCsException &cse ) { Q_UNUSED( cse ); QgsMessageLog::logMessage( QObject::tr( "Caught a coordinate system exception while trying to transform a point. Unable to calculate line length." ) ); return 0.0; } } ///////////////////////////////////////////////////////////
 @@ -130,6 +130,11 @@ class CORE_EXPORT QgsDistanceArea double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2, double* course1 = NULL, double* course2 = NULL ); //! uses flat / planimetric / Euclidean distance double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ); //! calculate distance with given coordinates (does not do a transform anymore) double computeDistance( const QList& points ); /** calculates area of polygon on ellipsoid