mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Fix area calculation when OTF active and no ellipsoid (fix #13601)
This commit is contained in:
parent
5ed3d1b73f
commit
5654eeca55
@ -701,6 +701,18 @@ class QgsGeometry
|
||||
|
||||
/** Creates and returns a new geometry engine*/
|
||||
static QgsGeometryEngine* createGeometryEngine( const QgsAbstractGeometryV2* geometry ) /Factory/;
|
||||
|
||||
/** Upgrades a point list from QgsPoint to QgsPointV2
|
||||
* @param input list of QgsPoint objects to be upgraded
|
||||
* @param output destination for list of points converted to QgsPointV2
|
||||
*/
|
||||
static void convertPointList( const QList<QgsPoint>& input, QList<QgsPointV2>& output );
|
||||
|
||||
/** Downgrades a point list from QgsPointV2 to QgsPoint
|
||||
* @param input list of QgsPointV2 objects to be downgraded
|
||||
* @param output destination for list of points converted to QgsPoint
|
||||
*/
|
||||
static void convertPointList( const QList<QgsPointV2>& input, QList<QgsPoint>& output );
|
||||
|
||||
}; // class QgsGeometry
|
||||
|
||||
|
@ -746,8 +746,16 @@ class CORE_EXPORT QgsGeometry
|
||||
*/
|
||||
static QgsGeometryEngine* createGeometryEngine( const QgsAbstractGeometryV2* geometry );
|
||||
|
||||
//convert point list from v1 to v2
|
||||
/** Upgrades a point list from QgsPoint to QgsPointV2
|
||||
* @param input list of QgsPoint objects to be upgraded
|
||||
* @param output destination for list of points converted to QgsPointV2
|
||||
*/
|
||||
static void convertPointList( const QList<QgsPoint>& input, QList<QgsPointV2>& output );
|
||||
|
||||
/** Downgrades a point list from QgsPointV2 to QgsPoint
|
||||
* @param input list of QgsPointV2 objects to be downgraded
|
||||
* @param output destination for list of points converted to QgsPoint
|
||||
*/
|
||||
static void convertPointList( const QList<QgsPointV2>& input, QList<QgsPoint>& output );
|
||||
|
||||
private:
|
||||
|
@ -276,8 +276,9 @@ double QgsDistanceArea::measure( const QgsAbstractGeometryV2* geomV2 ) const
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if ( !mEllipsoidalMode )
|
||||
if ( !mEllipsoidalMode || mEllipsoid == GEO_NONE )
|
||||
{
|
||||
//no transform required
|
||||
if ( geomDimension == 1 )
|
||||
{
|
||||
return geomV2->length();
|
||||
@ -296,6 +297,8 @@ double QgsDistanceArea::measure( const QgsAbstractGeometryV2* geomV2 ) const
|
||||
double sum = 0;
|
||||
for ( int i = 0; i < collection->numGeometries(); ++i )
|
||||
{
|
||||
//hmm... this is a bit broken. What if a collection consists of both lines and polygons?
|
||||
//the sum will be a mash of both areas and lengths
|
||||
sum += measure( collection->geometryN( i ) );
|
||||
}
|
||||
return sum;
|
||||
@ -596,15 +599,9 @@ double QgsDistanceArea::measurePolygon( const QgsCurveV2* curve ) const
|
||||
|
||||
QList<QgsPointV2> linePointsV2;
|
||||
curve->points( linePointsV2 );
|
||||
|
||||
QList<QgsPoint> linePoints;
|
||||
QList<QgsPointV2>::const_iterator ptIt = linePointsV2.constBegin();
|
||||
for ( ; ptIt != linePointsV2.constEnd(); ++ptIt )
|
||||
{
|
||||
linePoints.append( mCoordTransform->transform( QPoint( ptIt->x(), ptIt->y() ) ) );
|
||||
}
|
||||
|
||||
return computePolygonArea( linePoints );
|
||||
QgsGeometry::convertPointList( linePointsV2, linePoints );
|
||||
return measurePolygon( linePoints );
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include <qgsdistancearea.h>
|
||||
#include <qgspoint.h>
|
||||
#include "qgslogger.h"
|
||||
#include "qgsgeometryfactory.h"
|
||||
#include "qgsgeometry.h"
|
||||
|
||||
class TestQgsDistanceArea: public QObject
|
||||
{
|
||||
@ -34,6 +36,7 @@ class TestQgsDistanceArea: public QObject
|
||||
void basic();
|
||||
void test_distances();
|
||||
void unit_conversions();
|
||||
void regression13601();
|
||||
};
|
||||
|
||||
void TestQgsDistanceArea::initTestCase()
|
||||
@ -163,7 +166,18 @@ void TestQgsDistanceArea::unit_conversions()
|
||||
QString myTxt = QgsDistanceArea::textUnit( inputValue, 7, inputUnit, true, false );
|
||||
QString expectedTxt = QLocale::system().toString( 2.4710538146717, 'g', 1 + 7 );
|
||||
QVERIFY( myTxt.startsWith( expectedTxt ) ); // Ignore units for now.
|
||||
};
|
||||
}
|
||||
|
||||
void TestQgsDistanceArea::regression13601()
|
||||
{
|
||||
//test regression #13601
|
||||
QgsDistanceArea calc;
|
||||
calc.setEllipsoidalMode( true );
|
||||
calc.setEllipsoid( "NONE" );
|
||||
calc.setSourceCrs( 1108L );
|
||||
QgsGeometry geom( QgsGeometryFactory::geomFromWkt("Polygon ((252000 1389000, 265000 1389000, 265000 1385000, 252000 1385000, 252000 1389000))") );
|
||||
QVERIFY( qgsDoubleNear( calc.measure( &geom ), 52000000, 0.0001 ) );
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsDistanceArea )
|
||||
#include "testqgsdistancearea.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user