23QString QgsTranslateAlgorithm::name()
const
25 return QStringLiteral(
"translategeometry" );
28QString QgsTranslateAlgorithm::displayName()
const
30 return QObject::tr(
"Translate" );
33QStringList QgsTranslateAlgorithm::tags()
const
35 return QObject::tr(
"move,shift,transform,z,m,values,add" ).split(
',' );
38QString QgsTranslateAlgorithm::group()
const
40 return QObject::tr(
"Vector geometry" );
43QString QgsTranslateAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeometry" );
48QString QgsTranslateAlgorithm::outputName()
const
50 return QObject::tr(
"Translated" );
53QString 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." );
60QgsTranslateAlgorithm *QgsTranslateAlgorithm::createInstance()
const
62 return new QgsTranslateAlgorithm();
65void QgsTranslateAlgorithm::initParameters(
const QVariantMap & )
67 std::unique_ptr<QgsProcessingParameterDistance> xOffset = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DELTA_X" ), QObject::tr(
"Offset distance (x-axis)" ), 0.0, QStringLiteral(
"INPUT" ) );
68 xOffset->setIsDynamic(
true );
70 xOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
71 addParameter( xOffset.release() );
73 std::unique_ptr<QgsProcessingParameterDistance> yOffset = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DELTA_Y" ), QObject::tr(
"Offset distance (y-axis)" ), 0.0, QStringLiteral(
"INPUT" ) );
74 yOffset->setIsDynamic(
true );
76 yOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
77 addParameter( yOffset.release() );
79 std::unique_ptr<QgsProcessingParameterNumber> zOffset = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"DELTA_Z" ), QObject::tr(
"Offset distance (z-axis)" ),
Qgis::ProcessingNumberParameterType::Double, 0.0 );
80 zOffset->setIsDynamic(
true );
82 zOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
83 addParameter( zOffset.release() );
85 std::unique_ptr<QgsProcessingParameterNumber> mOffset = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"DELTA_M" ), QObject::tr(
"Offset distance (m values)" ),
Qgis::ProcessingNumberParameterType::Double, 0.0 );
86 mOffset->setIsDynamic(
true );
88 mOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
89 addParameter( mOffset.release() );
94 mDeltaX = parameterAsDouble( parameters, QStringLiteral(
"DELTA_X" ), context );
97 mDeltaXProperty = parameters.value( QStringLiteral(
"DELTA_X" ) ).value<
QgsProperty>();
99 mDeltaY = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Y" ), context );
101 if ( mDynamicDeltaY )
102 mDeltaYProperty = parameters.value( QStringLiteral(
"DELTA_Y" ) ).value<
QgsProperty>();
104 mDeltaZ = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Z" ), context );
106 if ( mDynamicDeltaZ )
107 mDeltaZProperty = parameters.value( QStringLiteral(
"DELTA_Z" ) ).value<
QgsProperty>();
109 mDeltaM = parameterAsDouble( parameters, QStringLiteral(
"DELTA_M" ), context );
111 if ( mDynamicDeltaM )
112 mDeltaMProperty = parameters.value( QStringLiteral(
"DELTA_M" ) ).value<
QgsProperty>();
124 double deltaX = mDeltaX;
125 if ( mDynamicDeltaX )
127 double deltaY = mDeltaY;
128 if ( mDynamicDeltaY )
130 double deltaZ = mDeltaZ;
131 if ( mDynamicDeltaZ )
133 double deltaM = mDeltaM;
134 if ( mDynamicDeltaM )
142 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
151 if ( mDeltaZ != 0.0 )
153 if ( mDeltaM != 0.0 )
159bool QgsTranslateAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
161 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
169 if ( mDeltaX != 0.0 || mDeltaY != 0.0 )
174 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 data sets.
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.
QList< QgsFeature > QgsFeatureList