22 QString QgsTranslateAlgorithm::name()
const 24 return QStringLiteral(
"translategeometry" );
27 QString QgsTranslateAlgorithm::displayName()
const 29 return QObject::tr(
"Translate" );
32 QStringList QgsTranslateAlgorithm::tags()
const 34 return QObject::tr(
"move,shift,transform,z,m,values,add" ).split(
',' );
37 QString QgsTranslateAlgorithm::group()
const 39 return QObject::tr(
"Vector geometry" );
42 QString QgsTranslateAlgorithm::groupId()
const 44 return QStringLiteral(
"vectorgeometry" );
47 QString QgsTranslateAlgorithm::outputName()
const 49 return QObject::tr(
"Translated" );
52 QString QgsTranslateAlgorithm::shortHelpString()
const 54 return QObject::tr(
"This algorithm moves the geometries within a layer, by offsetting them with a specified x and y displacement." )
55 + QStringLiteral(
"\n\n" )
56 + QObject::tr(
"Z and M values present in the geometry can also be translated." );
59 QgsTranslateAlgorithm *QgsTranslateAlgorithm::createInstance()
const 61 return new QgsTranslateAlgorithm();
64 void QgsTranslateAlgorithm::initParameters(
const QVariantMap & )
66 std::unique_ptr< QgsProcessingParameterDistance > xOffset = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DELTA_X" ),
67 QObject::tr(
"Offset distance (x-axis)" ),
68 0.0, QStringLiteral(
"INPUT" ) );
69 xOffset->setIsDynamic(
true );
71 xOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
72 addParameter( xOffset.release() );
74 std::unique_ptr< QgsProcessingParameterDistance > yOffset = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DELTA_Y" ),
75 QObject::tr(
"Offset distance (y-axis)" ),
76 0.0, QStringLiteral(
"INPUT" ) );
77 yOffset->setIsDynamic(
true );
79 yOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
80 addParameter( yOffset.release() );
82 std::unique_ptr< QgsProcessingParameterNumber > zOffset = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DELTA_Z" ),
85 zOffset->setIsDynamic(
true );
87 zOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
88 addParameter( zOffset.release() );
90 std::unique_ptr< QgsProcessingParameterNumber > mOffset = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DELTA_M" ),
93 mOffset->setIsDynamic(
true );
95 mOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
96 addParameter( mOffset.release() );
101 mDeltaX = parameterAsDouble( parameters, QStringLiteral(
"DELTA_X" ), context );
103 if ( mDynamicDeltaX )
104 mDeltaXProperty = parameters.value( QStringLiteral(
"DELTA_X" ) ).value<
QgsProperty >();
106 mDeltaY = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Y" ), context );
108 if ( mDynamicDeltaY )
109 mDeltaYProperty = parameters.value( QStringLiteral(
"DELTA_Y" ) ).value<
QgsProperty >();
111 mDeltaZ = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Z" ), context );
113 if ( mDynamicDeltaZ )
114 mDeltaZProperty = parameters.value( QStringLiteral(
"DELTA_Z" ) ).value<
QgsProperty >();
116 mDeltaM = parameterAsDouble( parameters, QStringLiteral(
"DELTA_M" ), context );
118 if ( mDynamicDeltaM )
119 mDeltaMProperty = parameters.value( QStringLiteral(
"DELTA_M" ) ).value<
QgsProperty >();
131 double deltaX = mDeltaX;
132 if ( mDynamicDeltaX )
134 double deltaY = mDeltaY;
135 if ( mDynamicDeltaY )
137 double deltaZ = mDeltaZ;
138 if ( mDynamicDeltaZ )
140 double deltaM = mDeltaM;
141 if ( mDynamicDeltaM )
149 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
bool isMeasure() const
Returns true if the geometry contains m values.
Base class for providing feedback from a processing algorithm.
QList< QgsFeature > QgsFeatureList
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
A geometry is the spatial representation of a feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Type
The WKB type describes the number of dimensions a geometry has.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
A store for object properties.
Double value (including negative values)
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition for a property.
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.
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.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
Contains information about the context in which a processing algorithm is executed.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
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...