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 );