23QString QgsAffineTransformationAlgorithm::name()
const
25 return QStringLiteral(
"affinetransform" );
28QString QgsAffineTransformationAlgorithm::displayName()
const
30 return QObject::tr(
"Affine transform" );
33QStringList QgsAffineTransformationAlgorithm::tags()
const
35 return QObject::tr(
"move,shift,transform,affine,scale,rotate,resize,matrix" ).split(
',' );
38QString QgsAffineTransformationAlgorithm::group()
const
40 return QObject::tr(
"Vector geometry" );
43QString QgsAffineTransformationAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeometry" );
48QString QgsAffineTransformationAlgorithm::outputName()
const
50 return QObject::tr(
"Transformed" );
53QString QgsAffineTransformationAlgorithm::shortHelpString()
const
55 return QObject::tr(
"Applies an affine transformation to the geometries from a layer. Affine transformations can include "
56 "translation, scaling and rotation. The operations are performed in a scale, rotation, translation order." )
57 + QStringLiteral(
"\n\n" )
58 + QObject::tr(
"Z and M values present in the geometry can also be translated and scaled independently." );
61QString QgsAffineTransformationAlgorithm::shortDescription()
const
63 return QObject::tr(
"Applies an affine transformation to geometries." );
66QgsAffineTransformationAlgorithm *QgsAffineTransformationAlgorithm::createInstance()
const
68 return new QgsAffineTransformationAlgorithm();
71void QgsAffineTransformationAlgorithm::initParameters(
const QVariantMap & )
73 std::unique_ptr< QgsProcessingParameterDistance > xOffset = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DELTA_X" ),
74 QObject::tr(
"Translation (x-axis)" ),
75 0.0, QStringLiteral(
"INPUT" ) );
76 xOffset->setIsDynamic(
true );
78 xOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
79 addParameter( xOffset.release() );
81 std::unique_ptr< QgsProcessingParameterDistance > yOffset = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DELTA_Y" ),
82 QObject::tr(
"Translation (y-axis)" ),
83 0.0, QStringLiteral(
"INPUT" ) );
84 yOffset->setIsDynamic(
true );
86 yOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
87 addParameter( yOffset.release() );
89 std::unique_ptr< QgsProcessingParameterNumber > zOffset = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DELTA_Z" ),
92 zOffset->setIsDynamic(
true );
94 zOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
95 addParameter( zOffset.release() );
97 std::unique_ptr< QgsProcessingParameterNumber > mOffset = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DELTA_M" ),
100 mOffset->setIsDynamic(
true );
102 mOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
103 addParameter( mOffset.release() );
105 std::unique_ptr< QgsProcessingParameterNumber > xScale = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"SCALE_X" ),
108 xScale->setIsDynamic(
true );
110 xScale->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
111 addParameter( xScale.release() );
113 std::unique_ptr< QgsProcessingParameterNumber > yScale = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"SCALE_Y" ),
116 yScale->setIsDynamic(
true );
118 yScale->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
119 addParameter( yScale.release() );
121 std::unique_ptr< QgsProcessingParameterNumber > zScale = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"SCALE_Z" ),
124 zScale->setIsDynamic(
true );
126 zScale->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
127 addParameter( zScale.release() );
129 std::unique_ptr< QgsProcessingParameterNumber > mScale = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"SCALE_M" ),
132 mScale->setIsDynamic(
true );
134 mScale->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
135 addParameter( mScale.release() );
137 std::unique_ptr< QgsProcessingParameterNumber > rotation = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ROTATION_Z" ),
140 rotation->setIsDynamic(
true );
142 rotation->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
143 addParameter( rotation.release() );
148 mDeltaX = parameterAsDouble( parameters, QStringLiteral(
"DELTA_X" ), context );
150 if ( mDynamicDeltaX )
151 mDeltaXProperty = parameters.value( QStringLiteral(
"DELTA_X" ) ).value<
QgsProperty >();
153 mDeltaY = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Y" ), context );
155 if ( mDynamicDeltaY )
156 mDeltaYProperty = parameters.value( QStringLiteral(
"DELTA_Y" ) ).value<
QgsProperty >();
158 mDeltaZ = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Z" ), context );
160 if ( mDynamicDeltaZ )
161 mDeltaZProperty = parameters.value( QStringLiteral(
"DELTA_Z" ) ).value<
QgsProperty >();
163 mDeltaM = parameterAsDouble( parameters, QStringLiteral(
"DELTA_M" ), context );
165 if ( mDynamicDeltaM )
166 mDeltaMProperty = parameters.value( QStringLiteral(
"DELTA_M" ) ).value<
QgsProperty >();
168 mScaleX = parameterAsDouble( parameters, QStringLiteral(
"SCALE_X" ), context );
170 if ( mDynamicScaleX )
171 mScaleXProperty = parameters.value( QStringLiteral(
"SCALE_X" ) ).value<
QgsProperty >();
173 mScaleY = parameterAsDouble( parameters, QStringLiteral(
"SCALE_Y" ), context );
175 if ( mDynamicScaleY )
176 mScaleYProperty = parameters.value( QStringLiteral(
"SCALE_Y" ) ).value<
QgsProperty >();
178 mScaleZ = parameterAsDouble( parameters, QStringLiteral(
"SCALE_Z" ), context );
180 if ( mDynamicScaleZ )
181 mScaleZProperty = parameters.value( QStringLiteral(
"SCALE_Z" ) ).value<
QgsProperty >();
183 mScaleM = parameterAsDouble( parameters, QStringLiteral(
"SCALE_M" ), context );
185 if ( mDynamicScaleM )
186 mScaleMProperty = parameters.value( QStringLiteral(
"SCALE_M" ) ).value<
QgsProperty >();
188 mRotationZ = parameterAsDouble( parameters, QStringLiteral(
"ROTATION_Z" ), context );
190 if ( mDynamicRotationZ )
191 mRotationZProperty = parameters.value( QStringLiteral(
"ROTATION_Z" ) ).value<
QgsProperty >();
203 double deltaX = mDeltaX;
204 if ( mDynamicDeltaX )
206 double deltaY = mDeltaY;
207 if ( mDynamicDeltaY )
209 double deltaZ = mDeltaZ;
210 if ( mDynamicDeltaZ )
212 double deltaM = mDeltaM;
213 if ( mDynamicDeltaM )
221 double scaleX = mScaleX;
222 if ( mDynamicScaleX )
224 double scaleY = mScaleY;
225 if ( mDynamicScaleY )
227 double scaleZ = mScaleZ;
228 if ( mDynamicScaleZ )
230 double scaleM = mScaleM;
231 if ( mDynamicScaleM )
234 double rotationZ = mRotationZ;
235 if ( mDynamicRotationZ )
238 QTransform transform;
239 transform.translate( deltaX, deltaY );
240 transform.rotate( rotationZ );
241 transform.scale( scaleX, scaleY );
243 geometry.
transform( transform, deltaZ, scaleZ, deltaM, scaleM );
252 if ( mDeltaZ != 0.0 )
254 if ( mDeltaM != 0.0 )
260bool QgsAffineTransformationAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
262 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
271 return inPlaceWkbType == outputWkbType( inPlaceWkbType );
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
bool is3D() const SIP_HOLDGIL
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.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
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.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QgsAbstractGeometry * get()
Returns a modifiable (non-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.
@ Double
Double/float values.
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 data sets.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Type
The WKB type describes the number of dimensions a geometry has.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
QList< QgsFeature > QgsFeatureList