24using namespace Qt::StringLiterals;
28QString QgsTranslateAlgorithm::name()
const
30 return u
"translategeometry"_s;
33QString QgsTranslateAlgorithm::displayName()
const
35 return QObject::tr(
"Translate" );
38QStringList QgsTranslateAlgorithm::tags()
const
40 return QObject::tr(
"move,shift,transform,z,m,values,add" ).split(
',' );
43QString QgsTranslateAlgorithm::group()
const
45 return QObject::tr(
"Vector geometry" );
48QString QgsTranslateAlgorithm::groupId()
const
50 return u
"vectorgeometry"_s;
53QString QgsTranslateAlgorithm::outputName()
const
55 return QObject::tr(
"Translated" );
58QString QgsTranslateAlgorithm::shortHelpString()
const
60 return QObject::tr(
"This algorithm moves the geometries within a layer, by offsetting them with a specified x and y displacement." )
62 + QObject::tr(
"Z and M values present in the geometry can also be translated." );
65QString QgsTranslateAlgorithm::shortDescription()
const
67 return QObject::tr(
"Moves the geometries within a layer, by offsetting them with a specified x, y, z or m displacement." );
70QgsTranslateAlgorithm *QgsTranslateAlgorithm::createInstance()
const
72 return new QgsTranslateAlgorithm();
75void QgsTranslateAlgorithm::initParameters(
const QVariantMap & )
77 auto xOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_X"_s, QObject::tr(
"Offset distance (x-axis)" ), 0.0, u
"INPUT"_s );
78 xOffset->setIsDynamic(
true );
80 xOffset->setDynamicLayerParameterName( u
"INPUT"_s );
81 addParameter( xOffset.release() );
83 auto yOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_Y"_s, QObject::tr(
"Offset distance (y-axis)" ), 0.0, u
"INPUT"_s );
84 yOffset->setIsDynamic(
true );
86 yOffset->setDynamicLayerParameterName( u
"INPUT"_s );
87 addParameter( yOffset.release() );
90 zOffset->setIsDynamic(
true );
92 zOffset->setDynamicLayerParameterName( u
"INPUT"_s );
93 addParameter( zOffset.release() );
96 mOffset->setIsDynamic(
true );
98 mOffset->setDynamicLayerParameterName( u
"INPUT"_s );
99 addParameter( mOffset.release() );
104 mDeltaX = parameterAsDouble( parameters, u
"DELTA_X"_s, context );
106 if ( mDynamicDeltaX )
107 mDeltaXProperty = parameters.value( u
"DELTA_X"_s ).value<
QgsProperty>();
109 mDeltaY = parameterAsDouble( parameters, u
"DELTA_Y"_s, context );
111 if ( mDynamicDeltaY )
112 mDeltaYProperty = parameters.value( u
"DELTA_Y"_s ).value<
QgsProperty>();
114 mDeltaZ = parameterAsDouble( parameters, u
"DELTA_Z"_s, context );
116 if ( mDynamicDeltaZ )
117 mDeltaZProperty = parameters.value( u
"DELTA_Z"_s ).value<
QgsProperty>();
119 mDeltaM = parameterAsDouble( parameters, u
"DELTA_M"_s, context );
121 if ( mDynamicDeltaM )
122 mDeltaMProperty = parameters.value( u
"DELTA_M"_s ).value<
QgsProperty>();
134 double deltaX = mDeltaX;
135 if ( mDynamicDeltaX )
137 double deltaY = mDeltaY;
138 if ( mDynamicDeltaY )
140 double deltaZ = mDeltaZ;
141 if ( mDynamicDeltaZ )
143 double deltaM = mDeltaM;
144 if ( mDynamicDeltaM )
152 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
160 mOutputWkbType = inputWkbType;
161 if ( mDynamicDeltaZ || mDeltaZ != 0.0 )
163 if ( mDynamicDeltaM || mDeltaM != 0.0 )
165 return mOutputWkbType;
168bool QgsTranslateAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
170 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
178 if ( mDeltaX != 0.0 || mDeltaY != 0.0 )
183 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.
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.
Qgis::GeometryOperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
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.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
QList< QgsFeature > QgsFeatureList