24QString QgsAffineTransformationAlgorithm::name()
const
26 return QStringLiteral(
"affinetransform" );
29QString QgsAffineTransformationAlgorithm::displayName()
const
31 return QObject::tr(
"Affine transform" );
34QStringList QgsAffineTransformationAlgorithm::tags()
const
36 return QObject::tr(
"move,shift,transform,affine,scale,rotate,resize,matrix" ).split(
',' );
39QString QgsAffineTransformationAlgorithm::group()
const
41 return QObject::tr(
"Vector geometry" );
44QString QgsAffineTransformationAlgorithm::groupId()
const
46 return QStringLiteral(
"vectorgeometry" );
49QString QgsAffineTransformationAlgorithm::outputName()
const
51 return QObject::tr(
"Transformed" );
54QString QgsAffineTransformationAlgorithm::shortHelpString()
const
56 return QObject::tr(
"This algorithm applies an affine transformation to the geometries from a layer. Affine transformations can include "
57 "translation, scaling and rotation. The operations are performed in a scale, rotation, translation order." )
58 + QStringLiteral(
"\n\n" )
59 + QObject::tr(
"Z and M values present in the geometry can also be translated and scaled independently." );
62QString QgsAffineTransformationAlgorithm::shortDescription()
const
64 return QObject::tr(
"Applies an affine transformation to geometries." );
67QgsAffineTransformationAlgorithm *QgsAffineTransformationAlgorithm::createInstance()
const
69 return new QgsAffineTransformationAlgorithm();
72void QgsAffineTransformationAlgorithm::initParameters(
const QVariantMap & )
74 auto xOffset = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DELTA_X" ), QObject::tr(
"Translation (x-axis)" ), 0.0, QStringLiteral(
"INPUT" ) );
75 xOffset->setIsDynamic(
true );
77 xOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
78 addParameter( xOffset.release() );
80 auto yOffset = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DELTA_Y" ), QObject::tr(
"Translation (y-axis)" ), 0.0, QStringLiteral(
"INPUT" ) );
81 yOffset->setIsDynamic(
true );
83 yOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
84 addParameter( yOffset.release() );
87 zOffset->setIsDynamic(
true );
89 zOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
90 addParameter( zOffset.release() );
93 mOffset->setIsDynamic(
true );
95 mOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
96 addParameter( mOffset.release() );
99 xScale->setIsDynamic(
true );
101 xScale->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
102 addParameter( xScale.release() );
105 yScale->setIsDynamic(
true );
107 yScale->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
108 addParameter( yScale.release() );
111 zScale->setIsDynamic(
true );
113 zScale->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
114 addParameter( zScale.release() );
117 mScale->setIsDynamic(
true );
119 mScale->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
120 addParameter( mScale.release() );
122 auto rotation = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"ROTATION_Z" ), QObject::tr(
"Rotation around z-axis (degrees counter-clockwise)" ),
Qgis::ProcessingNumberParameterType::Double, 0.0 );
123 rotation->setIsDynamic(
true );
125 rotation->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
126 addParameter( rotation.release() );
131 mDeltaX = parameterAsDouble( parameters, QStringLiteral(
"DELTA_X" ), context );
133 if ( mDynamicDeltaX )
134 mDeltaXProperty = parameters.value( QStringLiteral(
"DELTA_X" ) ).value<
QgsProperty>();
136 mDeltaY = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Y" ), context );
138 if ( mDynamicDeltaY )
139 mDeltaYProperty = parameters.value( QStringLiteral(
"DELTA_Y" ) ).value<
QgsProperty>();
141 mDeltaZ = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Z" ), context );
143 if ( mDynamicDeltaZ )
144 mDeltaZProperty = parameters.value( QStringLiteral(
"DELTA_Z" ) ).value<
QgsProperty>();
146 mDeltaM = parameterAsDouble( parameters, QStringLiteral(
"DELTA_M" ), context );
148 if ( mDynamicDeltaM )
149 mDeltaMProperty = parameters.value( QStringLiteral(
"DELTA_M" ) ).value<
QgsProperty>();
151 mScaleX = parameterAsDouble( parameters, QStringLiteral(
"SCALE_X" ), context );
153 if ( mDynamicScaleX )
154 mScaleXProperty = parameters.value( QStringLiteral(
"SCALE_X" ) ).value<
QgsProperty>();
156 mScaleY = parameterAsDouble( parameters, QStringLiteral(
"SCALE_Y" ), context );
158 if ( mDynamicScaleY )
159 mScaleYProperty = parameters.value( QStringLiteral(
"SCALE_Y" ) ).value<
QgsProperty>();
161 mScaleZ = parameterAsDouble( parameters, QStringLiteral(
"SCALE_Z" ), context );
163 if ( mDynamicScaleZ )
164 mScaleZProperty = parameters.value( QStringLiteral(
"SCALE_Z" ) ).value<
QgsProperty>();
166 mScaleM = parameterAsDouble( parameters, QStringLiteral(
"SCALE_M" ), context );
168 if ( mDynamicScaleM )
169 mScaleMProperty = parameters.value( QStringLiteral(
"SCALE_M" ) ).value<
QgsProperty>();
171 mRotationZ = parameterAsDouble( parameters, QStringLiteral(
"ROTATION_Z" ), context );
173 if ( mDynamicRotationZ )
174 mRotationZProperty = parameters.value( QStringLiteral(
"ROTATION_Z" ) ).value<
QgsProperty>();
186 double deltaX = mDeltaX;
187 if ( mDynamicDeltaX )
189 double deltaY = mDeltaY;
190 if ( mDynamicDeltaY )
192 double deltaZ = mDeltaZ;
193 if ( mDynamicDeltaZ )
195 double deltaM = mDeltaM;
196 if ( mDynamicDeltaM )
204 double scaleX = mScaleX;
205 if ( mDynamicScaleX )
207 double scaleY = mScaleY;
208 if ( mDynamicScaleY )
210 double scaleZ = mScaleZ;
211 if ( mDynamicScaleZ )
213 double scaleM = mScaleM;
214 if ( mDynamicScaleM )
217 double rotationZ = mRotationZ;
218 if ( mDynamicRotationZ )
221 QTransform transform;
222 transform.translate( deltaX, deltaY );
223 transform.rotate( rotationZ );
224 transform.scale( scaleX, scaleY );
226 geometry.
transform( transform, deltaZ, scaleZ, deltaM, scaleM );
235 if ( mDeltaZ != 0.0 )
237 if ( mDeltaM != 0.0 )
243bool QgsAffineTransformationAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
245 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
254 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