Skip to content
Permalink
Browse files

Allow transform methods in QgsAbstractGeometry/QgsGeometry to also

transform z/m values via scale/translate arguments
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent 2b5aca5 commit dd223d9b080a611c5b6e6fd2a607317d1f29e666
@@ -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;
@@ -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;

@@ -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;

@@ -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 );
@@ -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
@@ -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;
@@ -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;
@@ -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;

@@ -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.
@@ -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;
}
}
}

@@ -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;
@@ -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();
}
@@ -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;
@@ -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();
}
@@ -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;
@@ -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,15 +2308,15 @@ 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 )
{
return QgsGeometry::InvalidBaseGeometry;
}

detach();
d->geometry->transform( ct );
d->geometry->transform( ct, zTranslate, zScale, mTranslate, mScale );
return QgsGeometry::Success;
}

@@ -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
@@ -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
}
@@ -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;

@@ -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();
}
@@ -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;
@@ -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;
}
}


@@ -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;

0 comments on commit dd223d9

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