22using namespace Qt::StringLiterals;
26QString QgsArrayTranslatedFeaturesAlgorithm::name()
const
28 return u
"arraytranslatedfeatures"_s;
31QString QgsArrayTranslatedFeaturesAlgorithm::displayName()
const
33 return QObject::tr(
"Array of translated features" );
36QStringList QgsArrayTranslatedFeaturesAlgorithm::tags()
const
38 return QObject::tr(
"translate,parallel,offset,duplicate,grid,spaced,moved,copy,features,objects,step,repeat" ).split(
',' );
41QString QgsArrayTranslatedFeaturesAlgorithm::group()
const
43 return QObject::tr(
"Vector creation" );
46QString QgsArrayTranslatedFeaturesAlgorithm::groupId()
const
48 return u
"vectorcreation"_s;
51QString QgsArrayTranslatedFeaturesAlgorithm::outputName()
const
53 return QObject::tr(
"Translated" );
56QString QgsArrayTranslatedFeaturesAlgorithm::shortHelpString()
const
59 "This algorithm creates copies of features in a layer, by creating multiple translated versions of each feature. "
60 "Each copy is incrementally displaced by a preset amount in the x/y/z/m axis."
64QString QgsArrayTranslatedFeaturesAlgorithm::shortDescription()
const
66 return QObject::tr(
"Creates multiple translated copies of features in a layer." );
74QgsArrayTranslatedFeaturesAlgorithm *QgsArrayTranslatedFeaturesAlgorithm::createInstance()
const
76 return new QgsArrayTranslatedFeaturesAlgorithm();
79void QgsArrayTranslatedFeaturesAlgorithm::initParameters(
const QVariantMap & )
82 count->setIsDynamic(
true );
84 count->setDynamicLayerParameterName( u
"INPUT"_s );
85 addParameter( count.release() );
87 auto xOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_X"_s, QObject::tr(
"Step distance (x-axis)" ), 0.0, u
"INPUT"_s );
88 xOffset->setIsDynamic(
true );
90 xOffset->setDynamicLayerParameterName( u
"INPUT"_s );
91 addParameter( xOffset.release() );
93 auto yOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_Y"_s, QObject::tr(
"Step distance (y-axis)" ), 0.0, u
"INPUT"_s );
94 yOffset->setIsDynamic(
true );
96 yOffset->setDynamicLayerParameterName( u
"INPUT"_s );
97 addParameter( yOffset.release() );
100 zOffset->setIsDynamic(
true );
102 zOffset->setDynamicLayerParameterName( u
"INPUT"_s );
103 addParameter( zOffset.release() );
106 mOffset->setIsDynamic(
true );
108 mOffset->setDynamicLayerParameterName( u
"INPUT"_s );
109 addParameter( mOffset.release() );
114 mCount = parameterAsInt( parameters, u
"COUNT"_s, context );
117 mCountProperty = parameters.value( u
"COUNT"_s ).value<
QgsProperty>();
119 mDeltaX = parameterAsDouble( parameters, u
"DELTA_X"_s, context );
121 if ( mDynamicDeltaX )
122 mDeltaXProperty = parameters.value( u
"DELTA_X"_s ).value<
QgsProperty>();
124 mDeltaY = parameterAsDouble( parameters, u
"DELTA_Y"_s, context );
126 if ( mDynamicDeltaY )
127 mDeltaYProperty = parameters.value( u
"DELTA_Y"_s ).value<
QgsProperty>();
129 mDeltaZ = parameterAsDouble( parameters, u
"DELTA_Z"_s, context );
131 if ( mDynamicDeltaZ )
132 mDeltaZProperty = parameters.value( u
"DELTA_Z"_s ).value<
QgsProperty>();
134 mDeltaM = parameterAsDouble( parameters, u
"DELTA_M"_s, context );
136 if ( mDynamicDeltaM )
137 mDeltaMProperty = parameters.value( u
"DELTA_M"_s ).value<
QgsProperty>();
154 result.reserve( count + 1 );
156 double deltaX = mDeltaX;
157 if ( mDynamicDeltaX )
159 double deltaY = mDeltaY;
160 if ( mDynamicDeltaY )
162 double deltaZ = mDeltaZ;
163 if ( mDynamicDeltaZ )
165 double deltaM = mDeltaM;
166 if ( mDynamicDeltaM )
179 outAttrs << QVariant( 0 );
184 for (
int i = 0; i < count; ++i )
187 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
190 outAttrs << QVariant( i + 1 );
192 result << offsetFeature;
213QgsFields QgsArrayTranslatedFeaturesAlgorithm::outputFields(
const QgsFields &inputFields )
const
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
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.
QFlags< SinkFlag > SinkFlags
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
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.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
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...
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
Definition for a property.
@ Double
Double value (including negative values).
@ IntegerPositiveGreaterZero
Non-zero positive integer 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.
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