From dd223d9b080a611c5b6e6fd2a607317d1f29e666 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 24 Nov 2017 15:34:35 +1000 Subject: [PATCH] Allow transform methods in QgsAbstractGeometry/QgsGeometry to also transform z/m values via scale/translate arguments --- python/core/geometry/qgsabstractgeometry.sip | 9 +- python/core/geometry/qgscircularstring.sip | 2 +- python/core/geometry/qgscompoundcurve.sip | 2 +- python/core/geometry/qgscurvepolygon.sip | 2 +- python/core/geometry/qgsgeometry.sip | 12 ++- .../core/geometry/qgsgeometrycollection.sip | 2 +- python/core/geometry/qgslinestring.sip | 2 +- python/core/geometry/qgspoint.sip | 2 +- src/core/geometry/qgsabstractgeometry.h | 9 +- src/core/geometry/qgscircularstring.cpp | 12 ++- src/core/geometry/qgscircularstring.h | 2 +- src/core/geometry/qgscompoundcurve.cpp | 4 +- src/core/geometry/qgscompoundcurve.h | 2 +- src/core/geometry/qgscurvepolygon.cpp | 6 +- src/core/geometry/qgscurvepolygon.h | 2 +- src/core/geometry/qgsgeometry.cpp | 8 +- src/core/geometry/qgsgeometry.h | 12 ++- src/core/geometry/qgsgeometrycollection.cpp | 4 +- src/core/geometry/qgsgeometrycollection.h | 2 +- src/core/geometry/qgslinestring.cpp | 12 ++- src/core/geometry/qgslinestring.h | 2 +- src/core/geometry/qgspoint.cpp | 11 ++- src/core/geometry/qgspoint.h | 2 +- tests/src/core/testqgsgeometry.cpp | 90 +++++++++++-------- 24 files changed, 135 insertions(+), 78 deletions(-) diff --git a/python/core/geometry/qgsabstractgeometry.sip b/python/core/geometry/qgsabstractgeometry.sip index 26793c5d093..cd28a5418d4 100644 --- a/python/core/geometry/qgsabstractgeometry.sip +++ b/python/core/geometry/qgsabstractgeometry.sip @@ -234,10 +234,13 @@ class QgsAbstractGeometry transform. %End - virtual void transform( const QTransform &t ) = 0; + virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, + double mTranslate = 0.0, double mScale = 1.0 ) = 0; %Docstring - Transforms the geometry using a QTransform object - \param t QTransform transformation + Transforms the x and y components of the geometry using a QTransform object ``t``. + + Optionally, the geometry's z values can be scaled via ``zScale`` and translated via ``zTranslate``. + Similarly, m-values can be scaled via ``mScale`` and translated via ``mTranslate``. %End virtual void draw( QPainter &p ) const = 0; diff --git a/python/core/geometry/qgscircularstring.sip b/python/core/geometry/qgscircularstring.sip index f91947cb200..4481f34e3c5 100644 --- a/python/core/geometry/qgscircularstring.sip +++ b/python/core/geometry/qgscircularstring.sip @@ -87,7 +87,7 @@ class QgsCircularString: QgsCurve virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ); - virtual void transform( const QTransform &t ); + virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); virtual void addToPainterPath( QPainterPath &path ) const; diff --git a/python/core/geometry/qgscompoundcurve.sip b/python/core/geometry/qgscompoundcurve.sip index 5c0eef93e24..8fba78c4876 100644 --- a/python/core/geometry/qgscompoundcurve.sip +++ b/python/core/geometry/qgscompoundcurve.sip @@ -112,7 +112,7 @@ class QgsCompoundCurve: QgsCurve virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ); - virtual void transform( const QTransform &t ); + virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); virtual void addToPainterPath( QPainterPath &path ) const; diff --git a/python/core/geometry/qgscurvepolygon.sip b/python/core/geometry/qgscurvepolygon.sip index e602d3c7864..04621bed534 100644 --- a/python/core/geometry/qgscurvepolygon.sip +++ b/python/core/geometry/qgscurvepolygon.sip @@ -131,7 +131,7 @@ Adds an interior ring to the geometry (takes ownership) virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ); - virtual void transform( const QTransform &t ); + virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); virtual bool insertVertex( QgsVertexId position, const QgsPoint &vertex ); diff --git a/python/core/geometry/qgsgeometry.sip b/python/core/geometry/qgsgeometry.sip index a1e90b2504e..3852bae3e6f 100644 --- a/python/core/geometry/qgsgeometry.sip +++ b/python/core/geometry/qgsgeometry.sip @@ -566,9 +566,9 @@ Returns true if WKB of the geometry is of WKBMulti* type :rtype: QgsGeometry %End - OperationResult translate( double dx, double dy ); + OperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 ); %Docstring - Translates this geometry by dx, dy + Translates this geometry by dx, dy, dz and dm. :return: OperationResult a result code: success or reason of failure :rtype: OperationResult %End @@ -580,9 +580,13 @@ Returns true if WKB of the geometry is of WKBMulti* type :rtype: OperationResult %End - OperationResult transform( const QTransform &ct ); + OperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); %Docstring - Transforms this geometry as described by QTransform ct + Transforms the x and y components of the geometry using a QTransform object ``t``. + + Optionally, the geometry's z values can be scaled via ``zScale`` and translated via ``zTranslate``. + Similarly, m-values can be scaled via ``mScale`` and translated via ``mTranslate``. + :return: OperationResult a result code: success or reason of failure :rtype: OperationResult %End diff --git a/python/core/geometry/qgsgeometrycollection.sip b/python/core/geometry/qgsgeometrycollection.sip index 6e97b64ffb0..0c05e7ffe85 100644 --- a/python/core/geometry/qgsgeometrycollection.sip +++ b/python/core/geometry/qgsgeometrycollection.sip @@ -83,7 +83,7 @@ Adds a geometry and takes ownership. Returns true in case of success. virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ); - virtual void transform( const QTransform &t ); + virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); virtual void draw( QPainter &p ) const; diff --git a/python/core/geometry/qgslinestring.sip b/python/core/geometry/qgslinestring.sip index bbeaad6907b..b74e8a69b2d 100644 --- a/python/core/geometry/qgslinestring.sip +++ b/python/core/geometry/qgslinestring.sip @@ -225,7 +225,7 @@ Closes the line string by appending the first point to the end of the line, if i virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ); - virtual void transform( const QTransform &t ); + virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); virtual void addToPainterPath( QPainterPath &path ) const; diff --git a/python/core/geometry/qgspoint.sip b/python/core/geometry/qgspoint.sip index 84b873e19cc..6bb1c493037 100644 --- a/python/core/geometry/qgspoint.sip +++ b/python/core/geometry/qgspoint.sip @@ -359,7 +359,7 @@ class QgsPoint: QgsAbstractGeometry virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ); - virtual void transform( const QTransform &t ); + virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); virtual QgsCoordinateSequence coordinateSequence() const; diff --git a/src/core/geometry/qgsabstractgeometry.h b/src/core/geometry/qgsabstractgeometry.h index dca52089a31..98c1dcbe383 100644 --- a/src/core/geometry/qgsabstractgeometry.h +++ b/src/core/geometry/qgsabstractgeometry.h @@ -262,10 +262,13 @@ class CORE_EXPORT QgsAbstractGeometry bool transformZ = false ) = 0; /** - * Transforms the geometry using a QTransform object - * \param t QTransform transformation + * Transforms the x and y components of the geometry using a QTransform object \a t. + * + * Optionally, the geometry's z values can be scaled via \a zScale and translated via \a zTranslate. + * Similarly, m-values can be scaled via \a mScale and translated via \a mTranslate. */ - virtual void transform( const QTransform &t ) = 0; + virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, + double mTranslate = 0.0, double mScale = 1.0 ) = 0; /** * Draws the geometry using the specified QPainter. diff --git a/src/core/geometry/qgscircularstring.cpp b/src/core/geometry/qgscircularstring.cpp index 71469906be3..24bc5262903 100644 --- a/src/core/geometry/qgscircularstring.cpp +++ b/src/core/geometry/qgscircularstring.cpp @@ -559,17 +559,27 @@ void QgsCircularString::transform( const QgsCoordinateTransform &ct, QgsCoordina } } -void QgsCircularString::transform( const QTransform &t ) +void QgsCircularString::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale ) { clearCache(); int nPoints = numPoints(); + bool hasZ = is3D(); + bool hasM = isMeasure(); for ( int i = 0; i < nPoints; ++i ) { qreal x, y; t.map( mX.at( i ), mY.at( i ), &x, &y ); mX[i] = x; mY[i] = y; + if ( hasZ ) + { + mZ[i] = mZ.at( i ) * zScale + zTranslate; + } + if ( hasM ) + { + mM[i] = mM.at( i ) * mScale + mTranslate; + } } } diff --git a/src/core/geometry/qgscircularstring.h b/src/core/geometry/qgscircularstring.h index 19c8efd1c3f..91559ec15a1 100644 --- a/src/core/geometry/qgscircularstring.h +++ b/src/core/geometry/qgscircularstring.h @@ -76,7 +76,7 @@ class CORE_EXPORT QgsCircularString: public QgsCurve void draw( QPainter &p ) const override; void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override; - void transform( const QTransform &t ) override; + void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override; void addToPainterPath( QPainterPath &path ) const override; void drawAsPolygon( QPainter &p ) const override; bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override; diff --git a/src/core/geometry/qgscompoundcurve.cpp b/src/core/geometry/qgscompoundcurve.cpp index 53673cd4ed1..ec65fcfd393 100644 --- a/src/core/geometry/qgscompoundcurve.cpp +++ b/src/core/geometry/qgscompoundcurve.cpp @@ -509,11 +509,11 @@ void QgsCompoundCurve::transform( const QgsCoordinateTransform &ct, QgsCoordinat clearCache(); } -void QgsCompoundCurve::transform( const QTransform &t ) +void QgsCompoundCurve::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale ) { for ( QgsCurve *curve : qgis::as_const( mCurves ) ) { - curve->transform( t ); + curve->transform( t, zTranslate, zScale, mTranslate, mScale ); } clearCache(); } diff --git a/src/core/geometry/qgscompoundcurve.h b/src/core/geometry/qgscompoundcurve.h index eae706480de..a487836d3bc 100644 --- a/src/core/geometry/qgscompoundcurve.h +++ b/src/core/geometry/qgscompoundcurve.h @@ -99,7 +99,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve void draw( QPainter &p ) const override; void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override; - void transform( const QTransform &t ) override; + void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override; void addToPainterPath( QPainterPath &path ) const override; void drawAsPolygon( QPainter &p ) const override; bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override; diff --git a/src/core/geometry/qgscurvepolygon.cpp b/src/core/geometry/qgscurvepolygon.cpp index a167e69cb3a..e3b552c948f 100644 --- a/src/core/geometry/qgscurvepolygon.cpp +++ b/src/core/geometry/qgscurvepolygon.cpp @@ -704,16 +704,16 @@ void QgsCurvePolygon::transform( const QgsCoordinateTransform &ct, QgsCoordinate clearCache(); } -void QgsCurvePolygon::transform( const QTransform &t ) +void QgsCurvePolygon::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale ) { if ( mExteriorRing ) { - mExteriorRing->transform( t ); + mExteriorRing->transform( t, zTranslate, zScale, mTranslate, mScale ); } for ( QgsCurve *curve : qgis::as_const( mInteriorRings ) ) { - curve->transform( t ); + curve->transform( t, zTranslate, zScale, mTranslate, mScale ); } clearCache(); } diff --git a/src/core/geometry/qgscurvepolygon.h b/src/core/geometry/qgscurvepolygon.h index a3eb971e9f2..a0c09207e94 100644 --- a/src/core/geometry/qgscurvepolygon.h +++ b/src/core/geometry/qgscurvepolygon.h @@ -111,7 +111,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface void draw( QPainter &p ) const override; void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override; - void transform( const QTransform &t ) override; + void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override; bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override; bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override; diff --git a/src/core/geometry/qgsgeometry.cpp b/src/core/geometry/qgsgeometry.cpp index 2de1ceab909..b6ec69307a0 100644 --- a/src/core/geometry/qgsgeometry.cpp +++ b/src/core/geometry/qgsgeometry.cpp @@ -752,7 +752,7 @@ QgsGeometry::OperationResult QgsGeometry::addPart( GEOSGeometry *newPart ) return QgsGeometryEditUtils::addPart( d->geometry.get(), std::move( geom ) ); } -QgsGeometry::OperationResult QgsGeometry::translate( double dx, double dy ) +QgsGeometry::OperationResult QgsGeometry::translate( double dx, double dy, double dz, double dm ) { if ( !d->geometry ) { @@ -761,7 +761,7 @@ QgsGeometry::OperationResult QgsGeometry::translate( double dx, double dy ) detach(); - d->geometry->transform( QTransform::fromTranslate( dx, dy ) ); + d->geometry->transform( QTransform::fromTranslate( dx, dy ), dz, 1.0, dm ); return QgsGeometry::Success; } @@ -2308,7 +2308,7 @@ QgsGeometry::OperationResult QgsGeometry::transform( const QgsCoordinateTransfor return QgsGeometry::Success; } -QgsGeometry::OperationResult QgsGeometry::transform( const QTransform &ct ) +QgsGeometry::OperationResult QgsGeometry::transform( const QTransform &ct, double zTranslate, double zScale, double mTranslate, double mScale ) { if ( !d->geometry ) { @@ -2316,7 +2316,7 @@ QgsGeometry::OperationResult QgsGeometry::transform( const QTransform &ct ) } detach(); - d->geometry->transform( ct ); + d->geometry->transform( ct, zTranslate, zScale, mTranslate, mScale ); return QgsGeometry::Success; } diff --git a/src/core/geometry/qgsgeometry.h b/src/core/geometry/qgsgeometry.h index 8bd9502d6de..09b866fc2cd 100644 --- a/src/core/geometry/qgsgeometry.h +++ b/src/core/geometry/qgsgeometry.h @@ -624,10 +624,10 @@ class CORE_EXPORT QgsGeometry QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const; /** - * Translates this geometry by dx, dy + * Translates this geometry by dx, dy, dz and dm. * \returns OperationResult a result code: success or reason of failure */ - OperationResult translate( double dx, double dy ); + OperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 ); /** * Transforms this geometry as described by CoordinateTransform ct @@ -636,10 +636,14 @@ class CORE_EXPORT QgsGeometry OperationResult transform( const QgsCoordinateTransform &ct ); /** - * Transforms this geometry as described by QTransform ct + * Transforms the x and y components of the geometry using a QTransform object \a t. + * + * Optionally, the geometry's z values can be scaled via \a zScale and translated via \a zTranslate. + * Similarly, m-values can be scaled via \a mScale and translated via \a mTranslate. + * * \returns OperationResult a result code: success or reason of failure */ - OperationResult transform( const QTransform &ct ); + OperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); /** * Rotate this geometry around the Z axis diff --git a/src/core/geometry/qgsgeometrycollection.cpp b/src/core/geometry/qgsgeometrycollection.cpp index 33289492573..de8b4a60d65 100644 --- a/src/core/geometry/qgsgeometrycollection.cpp +++ b/src/core/geometry/qgsgeometrycollection.cpp @@ -241,11 +241,11 @@ void QgsGeometryCollection::transform( const QgsCoordinateTransform &ct, QgsCoor clearCache(); //set bounding box invalid } -void QgsGeometryCollection::transform( const QTransform &t ) +void QgsGeometryCollection::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale ) { for ( QgsAbstractGeometry *g : qgis::as_const( mGeometries ) ) { - g->transform( t ); + g->transform( t, zTranslate, zScale, mTranslate, mScale ); } clearCache(); //set bounding box invalid } diff --git a/src/core/geometry/qgsgeometrycollection.h b/src/core/geometry/qgsgeometrycollection.h index 74c3022a4a2..0a631fb628a 100644 --- a/src/core/geometry/qgsgeometrycollection.h +++ b/src/core/geometry/qgsgeometrycollection.h @@ -88,7 +88,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override; - void transform( const QTransform &t ) override; + void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override; void draw( QPainter &p ) const override; diff --git a/src/core/geometry/qgslinestring.cpp b/src/core/geometry/qgslinestring.cpp index d1009479f4b..b5e9d4ae180 100644 --- a/src/core/geometry/qgslinestring.cpp +++ b/src/core/geometry/qgslinestring.cpp @@ -772,15 +772,25 @@ void QgsLineString::transform( const QgsCoordinateTransform &ct, QgsCoordinateTr clearCache(); } -void QgsLineString::transform( const QTransform &t ) +void QgsLineString::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale ) { int nPoints = numPoints(); + bool hasZ = is3D(); + bool hasM = isMeasure(); for ( int i = 0; i < nPoints; ++i ) { qreal x, y; t.map( mX.at( i ), mY.at( i ), &x, &y ); mX[i] = x; mY[i] = y; + if ( hasZ ) + { + mZ[i] = mZ.at( i ) * zScale + zTranslate; + } + if ( hasM ) + { + mM[i] = mM.at( i ) * mScale + mTranslate; + } } clearCache(); } diff --git a/src/core/geometry/qgslinestring.h b/src/core/geometry/qgslinestring.h index 76380c3c169..45c808ee644 100644 --- a/src/core/geometry/qgslinestring.h +++ b/src/core/geometry/qgslinestring.h @@ -210,7 +210,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override; - void transform( const QTransform &t ) override; + void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override; void addToPainterPath( QPainterPath &path ) const override; void drawAsPolygon( QPainter &p ) const override; diff --git a/src/core/geometry/qgspoint.cpp b/src/core/geometry/qgspoint.cpp index b0f23b53d35..fc9b13c9c9e 100644 --- a/src/core/geometry/qgspoint.cpp +++ b/src/core/geometry/qgspoint.cpp @@ -494,13 +494,22 @@ bool QgsPoint::addMValue( double mValue ) return true; } -void QgsPoint::transform( const QTransform &t ) +void QgsPoint::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale ) { clearCache(); qreal x, y; t.map( mX, mY, &x, &y ); mX = x; mY = y; + + if ( is3D() ) + { + mZ = mZ * zScale + zTranslate; + } + if ( isMeasure() ) + { + mM = mM * mScale + mTranslate; + } } diff --git a/src/core/geometry/qgspoint.h b/src/core/geometry/qgspoint.h index 9d41bd439c4..d6aa1a58783 100644 --- a/src/core/geometry/qgspoint.h +++ b/src/core/geometry/qgspoint.h @@ -403,7 +403,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry void draw( QPainter &p ) const override; void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override; - void transform( const QTransform &t ) override; + void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override; QgsCoordinateSequence coordinateSequence() const override; int nCoordinates() const override; int vertexNumberFromVertexId( QgsVertexId id ) const override; diff --git a/tests/src/core/testqgsgeometry.cpp b/tests/src/core/testqgsgeometry.cpp index f5ca1e5adc8..898a9e786fe 100644 --- a/tests/src/core/testqgsgeometry.cpp +++ b/tests/src/core/testqgsgeometry.cpp @@ -738,6 +738,8 @@ void TestQgsGeometry::point() QgsPoint p17( QgsWkbTypes::PointZM, 10, 20, 30, 40 ); p17.transform( qtr ); QVERIFY( p17 == QgsPoint( QgsWkbTypes::PointZM, 20, 60, 30, 40 ) ); + p17.transform( QTransform::fromScale( 1, 1 ), 11, 2, 3, 4 ); + QVERIFY( p17 == QgsPoint( QgsWkbTypes::PointZM, 20, 60, 71, 163 ) ); //coordinateSequence QgsPoint p18( QgsWkbTypes::PointZM, 1.0, 2.0, 3.0, 4.0 ); @@ -1644,6 +1646,12 @@ void TestQgsGeometry::circularString() QCOMPARE( l23.pointN( 1 ), QgsPoint( QgsWkbTypes::PointZM, 22, 36, 13, 14 ) ); QCOMPARE( l23.boundingBox(), QgsRectangle( 2, 6, 22, 36 ) ); + l23.setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointZM, 1, 2, 3, 4 ) + << QgsPoint( QgsWkbTypes::PointZM, 11, 12, 13, 14 ) ); + l23.transform( QTransform::fromScale( 1, 1 ), 3, 2, 4, 3 ); + QCOMPARE( l23.pointN( 0 ), QgsPoint( QgsWkbTypes::PointZM, 1, 2, 9, 16 ) ); + QCOMPARE( l23.pointN( 1 ), QgsPoint( QgsWkbTypes::PointZM, 11, 12, 29, 46 ) ); + //insert vertex //cannot insert vertex in empty line QgsCircularString l24; @@ -3318,6 +3326,12 @@ void TestQgsGeometry::lineString() QCOMPARE( l23.pointN( 1 ), QgsPoint( QgsWkbTypes::PointZM, 22, 36, 13, 14 ) ); QCOMPARE( l23.boundingBox(), QgsRectangle( 2, 6, 22, 36 ) ); + l23.setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointZM, 1, 2, 3, 4 ) + << QgsPoint( QgsWkbTypes::PointZM, 11, 12, 13, 14 ) ); + l23.transform( QTransform::fromScale( 1, 1 ), 3, 2, 4, 3 ); + QCOMPARE( l23.pointN( 0 ), QgsPoint( QgsWkbTypes::PointZM, 1, 2, 9, 16 ) ); + QCOMPARE( l23.pointN( 1 ), QgsPoint( QgsWkbTypes::PointZM, 11, 12, 29, 46 ) ); + //insert vertex //insert vertex in empty line @@ -5175,25 +5189,25 @@ void TestQgsGeometry::polygon() QgsPolygon pTransform2; pTransform2.setExteriorRing( l23.clone() ); pTransform2.addInteriorRing( l23.clone() ); - pTransform2.transform( qtr ); + pTransform2.transform( qtr, 2, 3, 4, 5 ); extR = static_cast< const QgsLineString * >( pTransform2.exteriorRing() ); QGSCOMPARENEAR( extR->pointN( 0 ).x(), 2, 100 ); QGSCOMPARENEAR( extR->pointN( 0 ).y(), 6, 100 ); - QGSCOMPARENEAR( extR->pointN( 0 ).z(), 3.0, 0.001 ); - QGSCOMPARENEAR( extR->pointN( 0 ).m(), 4.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 0 ).z(), 11.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 0 ).m(), 24.0, 0.001 ); QGSCOMPARENEAR( extR->pointN( 1 ).x(), 22, 100 ); QGSCOMPARENEAR( extR->pointN( 1 ).y(), 36, 100 ); - QGSCOMPARENEAR( extR->pointN( 1 ).z(), 13.0, 0.001 ); - QGSCOMPARENEAR( extR->pointN( 1 ).m(), 14.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 1 ).z(), 41.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 1 ).m(), 74.0, 0.001 ); QGSCOMPARENEAR( extR->pointN( 2 ).x(), 2, 100 ); QGSCOMPARENEAR( extR->pointN( 2 ).y(), 36, 100 ); - QGSCOMPARENEAR( extR->pointN( 2 ).z(), 23.0, 0.001 ); - QGSCOMPARENEAR( extR->pointN( 2 ).m(), 24.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 2 ).z(), 71.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 2 ).m(), 124.0, 0.001 ); QGSCOMPARENEAR( extR->pointN( 3 ).x(), 2, 100 ); QGSCOMPARENEAR( extR->pointN( 3 ).y(), 6, 100 ); - QGSCOMPARENEAR( extR->pointN( 3 ).z(), 3.0, 0.001 ); - QGSCOMPARENEAR( extR->pointN( 3 ).m(), 4.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 3 ).z(), 11.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 3 ).m(), 24.0, 0.001 ); QGSCOMPARENEAR( pTransform2.exteriorRing()->boundingBox().xMinimum(), 2, 0.001 ); QGSCOMPARENEAR( pTransform2.exteriorRing()->boundingBox().yMinimum(), 6, 0.001 ); QGSCOMPARENEAR( pTransform2.exteriorRing()->boundingBox().xMaximum(), 22, 0.001 ); @@ -5201,20 +5215,20 @@ void TestQgsGeometry::polygon() intR = static_cast< const QgsLineString * >( pTransform2.interiorRing( 0 ) ); QGSCOMPARENEAR( intR->pointN( 0 ).x(), 2, 100 ); QGSCOMPARENEAR( intR->pointN( 0 ).y(), 6, 100 ); - QGSCOMPARENEAR( intR->pointN( 0 ).z(), 3.0, 0.001 ); - QGSCOMPARENEAR( intR->pointN( 0 ).m(), 4.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 0 ).z(), 11.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 0 ).m(), 24.0, 0.001 ); QGSCOMPARENEAR( intR->pointN( 1 ).x(), 22, 100 ); QGSCOMPARENEAR( intR->pointN( 1 ).y(), 36, 100 ); - QGSCOMPARENEAR( intR->pointN( 1 ).z(), 13.0, 0.001 ); - QGSCOMPARENEAR( intR->pointN( 1 ).m(), 14.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 1 ).z(), 41.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 1 ).m(), 74.0, 0.001 ); QGSCOMPARENEAR( intR->pointN( 2 ).x(), 2, 100 ); QGSCOMPARENEAR( intR->pointN( 2 ).y(), 36, 100 ); - QGSCOMPARENEAR( intR->pointN( 2 ).z(), 23.0, 0.001 ); - QGSCOMPARENEAR( intR->pointN( 2 ).m(), 24.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 2 ).z(), 71.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 2 ).m(), 124.0, 0.001 ); QGSCOMPARENEAR( intR->pointN( 3 ).x(), 2, 100 ); QGSCOMPARENEAR( intR->pointN( 3 ).y(), 6, 100 ); - QGSCOMPARENEAR( intR->pointN( 3 ).z(), 3.0, 0.001 ); - QGSCOMPARENEAR( intR->pointN( 3 ).m(), 4.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 3 ).z(), 11.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 3 ).m(), 24.0, 0.001 ); QGSCOMPARENEAR( intR->boundingBox().xMinimum(), 2, 0.001 ); QGSCOMPARENEAR( intR->boundingBox().yMinimum(), 6, 0.001 ); QGSCOMPARENEAR( intR->boundingBox().xMaximum(), 22, 0.001 ); @@ -9309,13 +9323,13 @@ void TestQgsGeometry::compoundCurve() QgsLineString ls23; ls23.setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointZM, 11, 12, 13, 14 ) << QgsPoint( QgsWkbTypes::PointZM, 21, 13, 13, 14 ) ); c23.addCurve( ls23.clone() ); - c23.transform( qtr ); + c23.transform( qtr, 5, 2, 4, 3 ); c23.pointAt( 0, pt, v ); - QCOMPARE( pt, QgsPoint( QgsWkbTypes::PointZM, 2, 6, 3, 4 ) ); + QCOMPARE( pt, QgsPoint( QgsWkbTypes::PointZM, 2, 6, 11, 16 ) ); c23.pointAt( 1, pt, v ); - QCOMPARE( pt, QgsPoint( QgsWkbTypes::PointZM, 22, 36, 13, 14 ) ); + QCOMPARE( pt, QgsPoint( QgsWkbTypes::PointZM, 22, 36, 31, 46 ) ); c23.pointAt( 2, pt, v ); - QCOMPARE( pt, QgsPoint( QgsWkbTypes::PointZM, 42, 39, 13, 14 ) ); + QCOMPARE( pt, QgsPoint( QgsWkbTypes::PointZM, 42, 39, 31, 46 ) ); QCOMPARE( c23.boundingBox(), QgsRectangle( 2, 6, 42, 39 ) ); //insert vertex @@ -14144,25 +14158,25 @@ void TestQgsGeometry::geometryCollection() QgsGeometryCollection pTransform2; pTransform2.addGeometry( l23.clone() ); pTransform2.addGeometry( l23.clone() ); - pTransform2.transform( qtr ); + pTransform2.transform( qtr, 3, 2, 6, 3 ); extR = static_cast< const QgsLineString * >( pTransform2.geometryN( 0 ) ); QGSCOMPARENEAR( extR->pointN( 0 ).x(), 2, 100 ); QGSCOMPARENEAR( extR->pointN( 0 ).y(), 6, 100 ); - QGSCOMPARENEAR( extR->pointN( 0 ).z(), 3.0, 0.001 ); - QGSCOMPARENEAR( extR->pointN( 0 ).m(), 4.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 0 ).z(), 9.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 0 ).m(), 18.0, 0.001 ); QGSCOMPARENEAR( extR->pointN( 1 ).x(), 22, 100 ); QGSCOMPARENEAR( extR->pointN( 1 ).y(), 36, 100 ); - QGSCOMPARENEAR( extR->pointN( 1 ).z(), 13.0, 0.001 ); - QGSCOMPARENEAR( extR->pointN( 1 ).m(), 14.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 1 ).z(), 29.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 1 ).m(), 48.0, 0.001 ); QGSCOMPARENEAR( extR->pointN( 2 ).x(), 2, 100 ); QGSCOMPARENEAR( extR->pointN( 2 ).y(), 36, 100 ); - QGSCOMPARENEAR( extR->pointN( 2 ).z(), 23.0, 0.001 ); - QGSCOMPARENEAR( extR->pointN( 2 ).m(), 24.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 2 ).z(), 49.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 2 ).m(), 78.0, 0.001 ); QGSCOMPARENEAR( extR->pointN( 3 ).x(), 2, 100 ); QGSCOMPARENEAR( extR->pointN( 3 ).y(), 6, 100 ); - QGSCOMPARENEAR( extR->pointN( 3 ).z(), 3.0, 0.001 ); - QGSCOMPARENEAR( extR->pointN( 3 ).m(), 4.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 3 ).z(), 9.0, 0.001 ); + QGSCOMPARENEAR( extR->pointN( 3 ).m(), 18.0, 0.001 ); QGSCOMPARENEAR( extR->boundingBox().xMinimum(), 2, 0.001 ); QGSCOMPARENEAR( extR->boundingBox().yMinimum(), 6, 0.001 ); QGSCOMPARENEAR( extR->boundingBox().xMaximum(), 22, 0.001 ); @@ -14170,20 +14184,20 @@ void TestQgsGeometry::geometryCollection() intR = static_cast< const QgsLineString * >( pTransform2.geometryN( 1 ) ); QGSCOMPARENEAR( intR->pointN( 0 ).x(), 2, 100 ); QGSCOMPARENEAR( intR->pointN( 0 ).y(), 6, 100 ); - QGSCOMPARENEAR( intR->pointN( 0 ).z(), 3.0, 0.001 ); - QGSCOMPARENEAR( intR->pointN( 0 ).m(), 4.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 0 ).z(), 9.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 0 ).m(), 18.0, 0.001 ); QGSCOMPARENEAR( intR->pointN( 1 ).x(), 22, 100 ); QGSCOMPARENEAR( intR->pointN( 1 ).y(), 36, 100 ); - QGSCOMPARENEAR( intR->pointN( 1 ).z(), 13.0, 0.001 ); - QGSCOMPARENEAR( intR->pointN( 1 ).m(), 14.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 1 ).z(), 29.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 1 ).m(), 48.0, 0.001 ); QGSCOMPARENEAR( intR->pointN( 2 ).x(), 2, 100 ); QGSCOMPARENEAR( intR->pointN( 2 ).y(), 36, 100 ); - QGSCOMPARENEAR( intR->pointN( 2 ).z(), 23.0, 0.001 ); - QGSCOMPARENEAR( intR->pointN( 2 ).m(), 24.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 2 ).z(), 49.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 2 ).m(), 78.0, 0.001 ); QGSCOMPARENEAR( intR->pointN( 3 ).x(), 2, 100 ); QGSCOMPARENEAR( intR->pointN( 3 ).y(), 6, 100 ); - QGSCOMPARENEAR( intR->pointN( 3 ).z(), 3.0, 0.001 ); - QGSCOMPARENEAR( intR->pointN( 3 ).m(), 4.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 3 ).z(), 9.0, 0.001 ); + QGSCOMPARENEAR( intR->pointN( 3 ).m(), 18.0, 0.001 ); QGSCOMPARENEAR( intR->boundingBox().xMinimum(), 2, 0.001 ); QGSCOMPARENEAR( intR->boundingBox().yMinimum(), 6, 0.001 ); QGSCOMPARENEAR( intR->boundingBox().xMaximum(), 22, 0.001 );