22 QString QgsArrayTranslatedFeaturesAlgorithm::name()
const 24 return QStringLiteral(
"arraytranslatedfeatures" );
27 QString QgsArrayTranslatedFeaturesAlgorithm::displayName()
const 29 return QObject::tr(
"Array of translated features" );
32 QStringList QgsArrayTranslatedFeaturesAlgorithm::tags()
const 34 return QObject::tr(
"translate,parallel,offset,duplicate,grid,spaced,moved,copy,features,objects,step,repeat" ).split(
',' );
37 QString QgsArrayTranslatedFeaturesAlgorithm::group()
const 39 return QObject::tr(
"Vector creation" );
42 QString QgsArrayTranslatedFeaturesAlgorithm::groupId()
const 44 return QStringLiteral(
"vectorcreation" );
47 QString QgsArrayTranslatedFeaturesAlgorithm::outputName()
const 49 return QObject::tr(
"Translated" );
52 QString QgsArrayTranslatedFeaturesAlgorithm::shortHelpString()
const 54 return QObject::tr(
"This algorithm creates copies of features in a layer, by creating multiple translated versions of each feature. " 55 "Each copy is incrementally displaced by a preset amount in the x/y/z/m axis." );
58 QString QgsArrayTranslatedFeaturesAlgorithm::shortDescription()
const 60 return QObject::tr(
"Creates multiple translated copies of features in a layer." );
63 QgsArrayTranslatedFeaturesAlgorithm *QgsArrayTranslatedFeaturesAlgorithm::createInstance()
const 65 return new QgsArrayTranslatedFeaturesAlgorithm();
68 void QgsArrayTranslatedFeaturesAlgorithm::initParameters(
const QVariantMap & )
70 std::unique_ptr< QgsProcessingParameterNumber > count = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"COUNT" ),
73 count->setIsDynamic(
true );
75 count->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
76 addParameter( count.release() );
78 std::unique_ptr< QgsProcessingParameterDistance > xOffset = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DELTA_X" ),
79 QObject::tr(
"Step distance (x-axis)" ),
80 0.0, QStringLiteral(
"INPUT" ) );
81 xOffset->setIsDynamic(
true );
83 xOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
84 addParameter( xOffset.release() );
86 std::unique_ptr< QgsProcessingParameterDistance > yOffset = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"DELTA_Y" ),
87 QObject::tr(
"Step distance (y-axis)" ),
88 0.0, QStringLiteral(
"INPUT" ) );
89 yOffset->setIsDynamic(
true );
91 yOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
92 addParameter( yOffset.release() );
94 std::unique_ptr< QgsProcessingParameterNumber > zOffset = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DELTA_Z" ),
97 zOffset->setIsDynamic(
true );
99 zOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
100 addParameter( zOffset.release() );
102 std::unique_ptr< QgsProcessingParameterNumber > mOffset = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DELTA_M" ),
105 mOffset->setIsDynamic(
true );
107 mOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
108 addParameter( mOffset.release() );
113 mCount = parameterAsInt( parameters, QStringLiteral(
"COUNT" ), context );
116 mCountProperty = parameters.value( QStringLiteral(
"COUNT" ) ).value<
QgsProperty >();
118 mDeltaX = parameterAsDouble( parameters, QStringLiteral(
"DELTA_X" ), context );
120 if ( mDynamicDeltaX )
121 mDeltaXProperty = parameters.value( QStringLiteral(
"DELTA_X" ) ).value<
QgsProperty >();
123 mDeltaY = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Y" ), context );
125 if ( mDynamicDeltaY )
126 mDeltaYProperty = parameters.value( QStringLiteral(
"DELTA_Y" ) ).value<
QgsProperty >();
128 mDeltaZ = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Z" ), context );
130 if ( mDynamicDeltaZ )
131 mDeltaZProperty = parameters.value( QStringLiteral(
"DELTA_Z" ) ).value<
QgsProperty >();
133 mDeltaM = parameterAsDouble( parameters, QStringLiteral(
"DELTA_M" ), context );
135 if ( mDynamicDeltaM )
136 mDeltaMProperty = parameters.value( QStringLiteral(
"DELTA_M" ) ).value<
QgsProperty >();
153 result.reserve( count + 1 );
155 double deltaX = mDeltaX;
156 if ( mDynamicDeltaX )
158 double deltaY = mDeltaY;
159 if ( mDynamicDeltaY )
161 double deltaZ = mDeltaZ;
162 if ( mDynamicDeltaZ )
164 double deltaM = mDeltaM;
165 if ( mDynamicDeltaM )
178 outAttrs << QVariant( 0 );
183 for (
int i = 0; i < count; ++i )
186 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
189 outAttrs << QVariant( i + 1 );
191 result << offsetFeature;
212 QgsFields QgsArrayTranslatedFeaturesAlgorithm::outputFields(
const QgsFields &inputFields )
const 215 output.
append(
QgsField( QStringLiteral(
"instance" ), QVariant::Int ) );
219 QgsFeatureSink::SinkFlags QgsArrayTranslatedFeaturesAlgorithm::sinkFlags()
const bool isMeasure() const
Returns true if the geometry contains m values.
Base class for providing feedback from a processing algorithm.
QList< QgsFeature > QgsFeatureList
Non-zero positive integer values.
Container of fields for a vector layer.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
Type
The WKB type describes the number of dimensions a geometry has.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
A store for object properties.
Double value (including negative values)
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition for a property.
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.
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.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
Contains information about the context in which a processing algorithm is executed.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
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...