23 QString QgsTranslateAlgorithm::name()
const 25 return QStringLiteral(
"translategeometry" );
28 QString QgsTranslateAlgorithm::displayName()
const 30 return QObject::tr(
"Translate" );
33 QStringList QgsTranslateAlgorithm::tags()
const 35 return QObject::tr(
"move,shift,transform,z,m,values,add" ).split(
',' );
38 QString QgsTranslateAlgorithm::group()
const 40 return QObject::tr(
"Vector geometry" );
43 QString QgsTranslateAlgorithm::groupId()
const 45 return QStringLiteral(
"vectorgeometry" );
48 QString QgsTranslateAlgorithm::outputName()
const 50 return QObject::tr(
"Translated" );
53 QString QgsTranslateAlgorithm::shortHelpString()
const 55 return QObject::tr(
"This algorithm moves the geometries within a layer, by offsetting them with a specified x and y displacement." )
56 + QStringLiteral(
"\n\n" )
57 + QObject::tr(
"Z and M values present in the geometry can also be translated." );
60 QgsTranslateAlgorithm *QgsTranslateAlgorithm::createInstance()
const 62 return new QgsTranslateAlgorithm();
65 void QgsTranslateAlgorithm::initParameters(
const QVariantMap & )
67 std::unique_ptr< QgsProcessingParameterDistance > xOffset = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DELTA_X" ),
68 QObject::tr(
"Offset distance (x-axis)" ),
69 0.0, QStringLiteral(
"INPUT" ) );
70 xOffset->setIsDynamic(
true );
72 xOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
73 addParameter( xOffset.release() );
75 std::unique_ptr< QgsProcessingParameterDistance > yOffset = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DELTA_Y" ),
76 QObject::tr(
"Offset distance (y-axis)" ),
77 0.0, QStringLiteral(
"INPUT" ) );
78 yOffset->setIsDynamic(
true );
80 yOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
81 addParameter( yOffset.release() );
83 std::unique_ptr< QgsProcessingParameterNumber > zOffset = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DELTA_Z" ),
86 zOffset->setIsDynamic(
true );
88 zOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
89 addParameter( zOffset.release() );
91 std::unique_ptr< QgsProcessingParameterNumber > mOffset = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DELTA_M" ),
94 mOffset->setIsDynamic(
true );
96 mOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
97 addParameter( mOffset.release() );
102 mDeltaX = parameterAsDouble( parameters, QStringLiteral(
"DELTA_X" ), context );
104 if ( mDynamicDeltaX )
105 mDeltaXProperty = parameters.value( QStringLiteral(
"DELTA_X" ) ).value<
QgsProperty >();
107 mDeltaY = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Y" ), context );
109 if ( mDynamicDeltaY )
110 mDeltaYProperty = parameters.value( QStringLiteral(
"DELTA_Y" ) ).value<
QgsProperty >();
112 mDeltaZ = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Z" ), context );
114 if ( mDynamicDeltaZ )
115 mDeltaZProperty = parameters.value( QStringLiteral(
"DELTA_Z" ) ).value<
QgsProperty >();
117 mDeltaM = parameterAsDouble( parameters, QStringLiteral(
"DELTA_M" ), context );
119 if ( mDynamicDeltaM )
120 mDeltaMProperty = parameters.value( QStringLiteral(
"DELTA_M" ) ).value<
QgsProperty >();
132 double deltaX = mDeltaX;
133 if ( mDynamicDeltaX )
135 double deltaY = mDeltaY;
136 if ( mDynamicDeltaY )
138 double deltaZ = mDeltaZ;
139 if ( mDynamicDeltaZ )
141 double deltaM = mDeltaM;
142 if ( mDynamicDeltaM )
150 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
159 if ( mDeltaZ != 0.0 )
161 if ( mDeltaM != 0.0 )
167 bool QgsTranslateAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const 177 if ( mDeltaX != 0.0 || mDeltaY != 0.0 )
182 return inPlaceWkbType == outputWkbType( inPlaceWkbType );
Base class for all map layer types.
Base class for providing feedback from a processing algorithm.
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
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...
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Type
The WKB type describes the number of dimensions a geometry has.
bool isMeasure() const
Returns true if the geometry contains m values.
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.
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.
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.
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.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
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...