Skip to content

Commit 5654eec

Browse files
committed
Fix area calculation when OTF active and no ellipsoid (fix #13601)
1 parent 5ed3d1b commit 5654eec

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

python/core/geometry/qgsgeometry.sip

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,18 @@ class QgsGeometry
701701

702702
/** Creates and returns a new geometry engine*/
703703
static QgsGeometryEngine* createGeometryEngine( const QgsAbstractGeometryV2* geometry ) /Factory/;
704+
705+
/** Upgrades a point list from QgsPoint to QgsPointV2
706+
* @param input list of QgsPoint objects to be upgraded
707+
* @param output destination for list of points converted to QgsPointV2
708+
*/
709+
static void convertPointList( const QList<QgsPoint>& input, QList<QgsPointV2>& output );
710+
711+
/** Downgrades a point list from QgsPointV2 to QgsPoint
712+
* @param input list of QgsPointV2 objects to be downgraded
713+
* @param output destination for list of points converted to QgsPoint
714+
*/
715+
static void convertPointList( const QList<QgsPointV2>& input, QList<QgsPoint>& output );
704716

705717
}; // class QgsGeometry
706718

src/core/geometry/qgsgeometry.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,16 @@ class CORE_EXPORT QgsGeometry
746746
*/
747747
static QgsGeometryEngine* createGeometryEngine( const QgsAbstractGeometryV2* geometry );
748748

749-
//convert point list from v1 to v2
749+
/** Upgrades a point list from QgsPoint to QgsPointV2
750+
* @param input list of QgsPoint objects to be upgraded
751+
* @param output destination for list of points converted to QgsPointV2
752+
*/
750753
static void convertPointList( const QList<QgsPoint>& input, QList<QgsPointV2>& output );
754+
755+
/** Downgrades a point list from QgsPointV2 to QgsPoint
756+
* @param input list of QgsPointV2 objects to be downgraded
757+
* @param output destination for list of points converted to QgsPoint
758+
*/
751759
static void convertPointList( const QList<QgsPointV2>& input, QList<QgsPoint>& output );
752760

753761
private:

src/core/qgsdistancearea.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ double QgsDistanceArea::measure( const QgsAbstractGeometryV2* geomV2 ) const
276276
return 0.0;
277277
}
278278

279-
if ( !mEllipsoidalMode )
279+
if ( !mEllipsoidalMode || mEllipsoid == GEO_NONE )
280280
{
281+
//no transform required
281282
if ( geomDimension == 1 )
282283
{
283284
return geomV2->length();
@@ -296,6 +297,8 @@ double QgsDistanceArea::measure( const QgsAbstractGeometryV2* geomV2 ) const
296297
double sum = 0;
297298
for ( int i = 0; i < collection->numGeometries(); ++i )
298299
{
300+
//hmm... this is a bit broken. What if a collection consists of both lines and polygons?
301+
//the sum will be a mash of both areas and lengths
299302
sum += measure( collection->geometryN( i ) );
300303
}
301304
return sum;
@@ -596,15 +599,9 @@ double QgsDistanceArea::measurePolygon( const QgsCurveV2* curve ) const
596599

597600
QList<QgsPointV2> linePointsV2;
598601
curve->points( linePointsV2 );
599-
600602
QList<QgsPoint> linePoints;
601-
QList<QgsPointV2>::const_iterator ptIt = linePointsV2.constBegin();
602-
for ( ; ptIt != linePointsV2.constEnd(); ++ptIt )
603-
{
604-
linePoints.append( mCoordTransform->transform( QPoint( ptIt->x(), ptIt->y() ) ) );
605-
}
606-
607-
return computePolygonArea( linePoints );
603+
QgsGeometry::convertPointList( linePointsV2, linePoints );
604+
return measurePolygon( linePoints );
608605
}
609606

610607

tests/src/core/testqgsdistancearea.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <qgsdistancearea.h>
2424
#include <qgspoint.h>
2525
#include "qgslogger.h"
26+
#include "qgsgeometryfactory.h"
27+
#include "qgsgeometry.h"
2628

2729
class TestQgsDistanceArea: public QObject
2830
{
@@ -34,6 +36,7 @@ class TestQgsDistanceArea: public QObject
3436
void basic();
3537
void test_distances();
3638
void unit_conversions();
39+
void regression13601();
3740
};
3841

3942
void TestQgsDistanceArea::initTestCase()
@@ -163,7 +166,18 @@ void TestQgsDistanceArea::unit_conversions()
163166
QString myTxt = QgsDistanceArea::textUnit( inputValue, 7, inputUnit, true, false );
164167
QString expectedTxt = QLocale::system().toString( 2.4710538146717, 'g', 1 + 7 );
165168
QVERIFY( myTxt.startsWith( expectedTxt ) ); // Ignore units for now.
166-
};
169+
}
170+
171+
void TestQgsDistanceArea::regression13601()
172+
{
173+
//test regression #13601
174+
QgsDistanceArea calc;
175+
calc.setEllipsoidalMode( true );
176+
calc.setEllipsoid( "NONE" );
177+
calc.setSourceCrs( 1108L );
178+
QgsGeometry geom( QgsGeometryFactory::geomFromWkt("Polygon ((252000 1389000, 265000 1389000, 265000 1385000, 252000 1385000, 252000 1389000))") );
179+
QVERIFY( qgsDoubleNear( calc.measure( &geom ), 52000000, 0.0001 ) );
180+
}
167181

168182
QTEST_MAIN( TestQgsDistanceArea )
169183
#include "testqgsdistancearea.moc"

0 commit comments

Comments
 (0)