24using namespace Qt::StringLiterals;
28QString QgsAffineTransformationAlgorithm::name()
const
30 return u
"affinetransform"_s;
33QString QgsAffineTransformationAlgorithm::displayName()
const
35 return QObject::tr(
"Affine transform" );
38QStringList QgsAffineTransformationAlgorithm::tags()
const
40 return QObject::tr(
"move,shift,transform,affine,scale,rotate,resize,matrix" ).split(
',' );
43QString QgsAffineTransformationAlgorithm::group()
const
45 return QObject::tr(
"Vector geometry" );
48QString QgsAffineTransformationAlgorithm::groupId()
const
50 return u
"vectorgeometry"_s;
53QString QgsAffineTransformationAlgorithm::outputName()
const
55 return QObject::tr(
"Transformed" );
58QString QgsAffineTransformationAlgorithm::shortHelpString()
const
60 return QObject::tr(
"This algorithm applies an affine transformation to the geometries from a layer. Affine transformations can include "
61 "translation, scaling and rotation. The operations are performed in a scale, rotation, translation order." )
63 + QObject::tr(
"Z and M values present in the geometry can also be translated and scaled independently." );
66QString QgsAffineTransformationAlgorithm::shortDescription()
const
68 return QObject::tr(
"Applies an affine transformation to geometries." );
71QgsAffineTransformationAlgorithm *QgsAffineTransformationAlgorithm::createInstance()
const
73 return new QgsAffineTransformationAlgorithm();
76void QgsAffineTransformationAlgorithm::initParameters(
const QVariantMap & )
78 auto xOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_X"_s, QObject::tr(
"Translation (x-axis)" ), 0.0, u
"INPUT"_s );
79 xOffset->setIsDynamic(
true );
81 xOffset->setDynamicLayerParameterName( u
"INPUT"_s );
82 addParameter( xOffset.release() );
84 auto yOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_Y"_s, QObject::tr(
"Translation (y-axis)" ), 0.0, u
"INPUT"_s );
85 yOffset->setIsDynamic(
true );
87 yOffset->setDynamicLayerParameterName( u
"INPUT"_s );
88 addParameter( yOffset.release() );
91 zOffset->setIsDynamic(
true );
93 zOffset->setDynamicLayerParameterName( u
"INPUT"_s );
94 addParameter( zOffset.release() );
97 mOffset->setIsDynamic(
true );
99 mOffset->setDynamicLayerParameterName( u
"INPUT"_s );
100 addParameter( mOffset.release() );
103 xScale->setIsDynamic(
true );
105 xScale->setDynamicLayerParameterName( u
"INPUT"_s );
106 addParameter( xScale.release() );
109 yScale->setIsDynamic(
true );
111 yScale->setDynamicLayerParameterName( u
"INPUT"_s );
112 addParameter( yScale.release() );
115 zScale->setIsDynamic(
true );
117 zScale->setDynamicLayerParameterName( u
"INPUT"_s );
118 addParameter( zScale.release() );
121 mScale->setIsDynamic(
true );
123 mScale->setDynamicLayerParameterName( u
"INPUT"_s );
124 addParameter( mScale.release() );
127 rotation->setIsDynamic(
true );
129 rotation->setDynamicLayerParameterName( u
"INPUT"_s );
130 addParameter( rotation.release() );
135 mDeltaX = parameterAsDouble( parameters, u
"DELTA_X"_s, context );
137 if ( mDynamicDeltaX )
138 mDeltaXProperty = parameters.value( u
"DELTA_X"_s ).value<
QgsProperty>();
140 mDeltaY = parameterAsDouble( parameters, u
"DELTA_Y"_s, context );
142 if ( mDynamicDeltaY )
143 mDeltaYProperty = parameters.value( u
"DELTA_Y"_s ).value<
QgsProperty>();
145 mDeltaZ = parameterAsDouble( parameters, u
"DELTA_Z"_s, context );
147 if ( mDynamicDeltaZ )
148 mDeltaZProperty = parameters.value( u
"DELTA_Z"_s ).value<
QgsProperty>();
150 mDeltaM = parameterAsDouble( parameters, u
"DELTA_M"_s, context );
152 if ( mDynamicDeltaM )
153 mDeltaMProperty = parameters.value( u
"DELTA_M"_s ).value<
QgsProperty>();
155 mScaleX = parameterAsDouble( parameters, u
"SCALE_X"_s, context );
157 if ( mDynamicScaleX )
158 mScaleXProperty = parameters.value( u
"SCALE_X"_s ).value<
QgsProperty>();
160 mScaleY = parameterAsDouble( parameters, u
"SCALE_Y"_s, context );
162 if ( mDynamicScaleY )
163 mScaleYProperty = parameters.value( u
"SCALE_Y"_s ).value<
QgsProperty>();
165 mScaleZ = parameterAsDouble( parameters, u
"SCALE_Z"_s, context );
167 if ( mDynamicScaleZ )
168 mScaleZProperty = parameters.value( u
"SCALE_Z"_s ).value<
QgsProperty>();
170 mScaleM = parameterAsDouble( parameters, u
"SCALE_M"_s, context );
172 if ( mDynamicScaleM )
173 mScaleMProperty = parameters.value( u
"SCALE_M"_s ).value<
QgsProperty>();
175 mRotationZ = parameterAsDouble( parameters, u
"ROTATION_Z"_s, context );
177 if ( mDynamicRotationZ )
178 mRotationZProperty = parameters.value( u
"ROTATION_Z"_s ).value<
QgsProperty>();
190 double deltaX = mDeltaX;
191 if ( mDynamicDeltaX )
193 double deltaY = mDeltaY;
194 if ( mDynamicDeltaY )
196 double deltaZ = mDeltaZ;
197 if ( mDynamicDeltaZ )
199 double deltaM = mDeltaM;
200 if ( mDynamicDeltaM )
208 double scaleX = mScaleX;
209 if ( mDynamicScaleX )
211 double scaleY = mScaleY;
212 if ( mDynamicScaleY )
214 double scaleZ = mScaleZ;
215 if ( mDynamicScaleZ )
217 double scaleM = mScaleM;
218 if ( mDynamicScaleM )
221 double rotationZ = mRotationZ;
222 if ( mDynamicRotationZ )
225 QTransform transform;
226 transform.translate( deltaX, deltaY );
227 transform.rotate( rotationZ );
228 transform.scale( scaleX, scaleY );
230 geometry.
transform( transform, deltaZ, scaleZ, deltaM, scaleM );
239 if ( mDeltaZ != 0.0 )
241 if ( mDeltaM != 0.0 )
247bool QgsAffineTransformationAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
249 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
258 return inPlaceWkbType == outputWkbType( inPlaceWkbType );
WkbType
The WKB type describes the number of dimensions a geometry has.
@ Double
Double/float values.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Base class for all map layer types.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
Base class for providing feedback from a processing algorithm.
static bool isDynamic(const QVariantMap ¶meters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
Definition for a property.
@ Double
Double value (including negative values).
A store for object properties.
double valueAsDouble(const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a double.
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE Qgis::WkbType wkbType() const final
Returns the WKBType or WKBUnknown in case of error.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
QList< QgsFeature > QgsFeatureList