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
61 "This algorithm applies an affine transformation to the geometries from a layer. Affine transformations can include "
62 "translation, scaling and rotation. The operations are performed in a scale, rotation, translation order."
65 + QObject::tr(
"Z and M values present in the geometry can also be translated and scaled independently." );
68QString QgsAffineTransformationAlgorithm::shortDescription()
const
70 return QObject::tr(
"Applies an affine transformation to geometries." );
73QgsAffineTransformationAlgorithm *QgsAffineTransformationAlgorithm::createInstance()
const
75 return new QgsAffineTransformationAlgorithm();
78void QgsAffineTransformationAlgorithm::initParameters(
const QVariantMap & )
80 auto xOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_X"_s, QObject::tr(
"Translation (x-axis)" ), 0.0, u
"INPUT"_s );
81 xOffset->setIsDynamic(
true );
83 xOffset->setDynamicLayerParameterName( u
"INPUT"_s );
84 addParameter( xOffset.release() );
86 auto yOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_Y"_s, QObject::tr(
"Translation (y-axis)" ), 0.0, u
"INPUT"_s );
87 yOffset->setIsDynamic(
true );
89 yOffset->setDynamicLayerParameterName( u
"INPUT"_s );
90 addParameter( yOffset.release() );
93 zOffset->setIsDynamic(
true );
95 zOffset->setDynamicLayerParameterName( u
"INPUT"_s );
96 addParameter( zOffset.release() );
99 mOffset->setIsDynamic(
true );
101 mOffset->setDynamicLayerParameterName( u
"INPUT"_s );
102 addParameter( mOffset.release() );
105 xScale->setIsDynamic(
true );
107 xScale->setDynamicLayerParameterName( u
"INPUT"_s );
108 addParameter( xScale.release() );
111 yScale->setIsDynamic(
true );
113 yScale->setDynamicLayerParameterName( u
"INPUT"_s );
114 addParameter( yScale.release() );
117 zScale->setIsDynamic(
true );
119 zScale->setDynamicLayerParameterName( u
"INPUT"_s );
120 addParameter( zScale.release() );
123 mScale->setIsDynamic(
true );
125 mScale->setDynamicLayerParameterName( u
"INPUT"_s );
126 addParameter( mScale.release() );
129 rotation->setIsDynamic(
true );
131 rotation->setDynamicLayerParameterName( u
"INPUT"_s );
132 addParameter( rotation.release() );
137 mDeltaX = parameterAsDouble( parameters, u
"DELTA_X"_s, context );
139 if ( mDynamicDeltaX )
140 mDeltaXProperty = parameters.value( u
"DELTA_X"_s ).value<
QgsProperty>();
142 mDeltaY = parameterAsDouble( parameters, u
"DELTA_Y"_s, context );
144 if ( mDynamicDeltaY )
145 mDeltaYProperty = parameters.value( u
"DELTA_Y"_s ).value<
QgsProperty>();
147 mDeltaZ = parameterAsDouble( parameters, u
"DELTA_Z"_s, context );
149 if ( mDynamicDeltaZ )
150 mDeltaZProperty = parameters.value( u
"DELTA_Z"_s ).value<
QgsProperty>();
152 mDeltaM = parameterAsDouble( parameters, u
"DELTA_M"_s, context );
154 if ( mDynamicDeltaM )
155 mDeltaMProperty = parameters.value( u
"DELTA_M"_s ).value<
QgsProperty>();
157 mScaleX = parameterAsDouble( parameters, u
"SCALE_X"_s, context );
159 if ( mDynamicScaleX )
160 mScaleXProperty = parameters.value( u
"SCALE_X"_s ).value<
QgsProperty>();
162 mScaleY = parameterAsDouble( parameters, u
"SCALE_Y"_s, context );
164 if ( mDynamicScaleY )
165 mScaleYProperty = parameters.value( u
"SCALE_Y"_s ).value<
QgsProperty>();
167 mScaleZ = parameterAsDouble( parameters, u
"SCALE_Z"_s, context );
169 if ( mDynamicScaleZ )
170 mScaleZProperty = parameters.value( u
"SCALE_Z"_s ).value<
QgsProperty>();
172 mScaleM = parameterAsDouble( parameters, u
"SCALE_M"_s, context );
174 if ( mDynamicScaleM )
175 mScaleMProperty = parameters.value( u
"SCALE_M"_s ).value<
QgsProperty>();
177 mRotationZ = parameterAsDouble( parameters, u
"ROTATION_Z"_s, context );
179 if ( mDynamicRotationZ )
180 mRotationZProperty = parameters.value( u
"ROTATION_Z"_s ).value<
QgsProperty>();
192 double deltaX = mDeltaX;
193 if ( mDynamicDeltaX )
195 double deltaY = mDeltaY;
196 if ( mDynamicDeltaY )
198 double deltaZ = mDeltaZ;
199 if ( mDynamicDeltaZ )
201 double deltaM = mDeltaM;
202 if ( mDynamicDeltaM )
210 double scaleX = mScaleX;
211 if ( mDynamicScaleX )
213 double scaleY = mScaleY;
214 if ( mDynamicScaleY )
216 double scaleZ = mScaleZ;
217 if ( mDynamicScaleZ )
219 double scaleM = mScaleM;
220 if ( mDynamicScaleM )
223 double rotationZ = mRotationZ;
224 if ( mDynamicRotationZ )
227 QTransform transform;
228 transform.translate( deltaX, deltaY );
229 transform.rotate( rotationZ );
230 transform.scale( scaleX, scaleY );
232 geometry.
transform( transform, deltaZ, scaleZ, deltaM, scaleM );
241 if ( mDeltaZ != 0.0 )
243 if ( mDeltaM != 0.0 )
249bool QgsAffineTransformationAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
251 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
260 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