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 = std::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 = std::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 = std::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 = std::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
169 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
177 if ( mDeltaX != 0.0 || mDeltaY != 0.0 )
182 return inPlaceWkbType == outputWkbType( inPlaceWkbType );
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
bool is3D() const SIP_HOLDGIL
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.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
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.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsAbstractGeometry * get()
Returns a modifiable (non-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.
@ Double
Double/float values.
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 QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Type
The WKB type describes the number of dimensions a geometry has.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
QList< QgsFeature > QgsFeatureList