24QString QgsTranslateAlgorithm::name()
const
26 return QStringLiteral(
"translategeometry" );
29QString QgsTranslateAlgorithm::displayName()
const
31 return QObject::tr(
"Translate" );
34QStringList QgsTranslateAlgorithm::tags()
const
36 return QObject::tr(
"move,shift,transform,z,m,values,add" ).split(
',' );
39QString QgsTranslateAlgorithm::group()
const
41 return QObject::tr(
"Vector geometry" );
44QString QgsTranslateAlgorithm::groupId()
const
46 return QStringLiteral(
"vectorgeometry" );
49QString QgsTranslateAlgorithm::outputName()
const
51 return QObject::tr(
"Translated" );
54QString QgsTranslateAlgorithm::shortHelpString()
const
56 return QObject::tr(
"This algorithm moves the geometries within a layer, by offsetting them with a specified x and y displacement." )
57 + QStringLiteral(
"\n\n" )
58 + QObject::tr(
"Z and M values present in the geometry can also be translated." );
61QString QgsTranslateAlgorithm::shortDescription()
const
63 return QObject::tr(
"Moves the geometries within a layer, by offsetting them with a specified x, y, z or m displacement." );
66QgsTranslateAlgorithm *QgsTranslateAlgorithm::createInstance()
const
68 return new QgsTranslateAlgorithm();
71void QgsTranslateAlgorithm::initParameters(
const QVariantMap & )
73 auto xOffset = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DELTA_X" ), QObject::tr(
"Offset distance (x-axis)" ), 0.0, QStringLiteral(
"INPUT" ) );
74 xOffset->setIsDynamic(
true );
76 xOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
77 addParameter( xOffset.release() );
79 auto yOffset = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DELTA_Y" ), QObject::tr(
"Offset distance (y-axis)" ), 0.0, QStringLiteral(
"INPUT" ) );
80 yOffset->setIsDynamic(
true );
82 yOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
83 addParameter( yOffset.release() );
86 zOffset->setIsDynamic(
true );
88 zOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
89 addParameter( zOffset.release() );
92 mOffset->setIsDynamic(
true );
94 mOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
95 addParameter( mOffset.release() );
100 mDeltaX = parameterAsDouble( parameters, QStringLiteral(
"DELTA_X" ), context );
102 if ( mDynamicDeltaX )
103 mDeltaXProperty = parameters.value( QStringLiteral(
"DELTA_X" ) ).value<
QgsProperty>();
105 mDeltaY = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Y" ), context );
107 if ( mDynamicDeltaY )
108 mDeltaYProperty = parameters.value( QStringLiteral(
"DELTA_Y" ) ).value<
QgsProperty>();
110 mDeltaZ = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Z" ), context );
112 if ( mDynamicDeltaZ )
113 mDeltaZProperty = parameters.value( QStringLiteral(
"DELTA_Z" ) ).value<
QgsProperty>();
115 mDeltaM = parameterAsDouble( parameters, QStringLiteral(
"DELTA_M" ), context );
117 if ( mDynamicDeltaM )
118 mDeltaMProperty = parameters.value( QStringLiteral(
"DELTA_M" ) ).value<
QgsProperty>();
130 double deltaX = mDeltaX;
131 if ( mDynamicDeltaX )
133 double deltaY = mDeltaY;
134 if ( mDynamicDeltaY )
136 double deltaZ = mDeltaZ;
137 if ( mDynamicDeltaZ )
139 double deltaM = mDeltaM;
140 if ( mDynamicDeltaM )
148 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
156 mOutputWkbType = inputWkbType;
157 if ( mDynamicDeltaZ || mDeltaZ != 0.0 )
159 if ( mDynamicDeltaM || mDeltaM != 0.0 )
161 return mOutputWkbType;
164bool QgsTranslateAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
166 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
174 if ( mDeltaX != 0.0 || mDeltaY != 0.0 )
179 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