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
58 return QObject::tr(
"This algorithm creates copies of features in a layer, by creating multiple translated versions of each feature. "
59 "Each copy is incrementally displaced by a preset amount in the x/y/z/m axis." );
62QString QgsArrayTranslatedFeaturesAlgorithm::shortDescription()
const
64 return QObject::tr(
"Creates multiple translated copies of features in a layer." );
72QgsArrayTranslatedFeaturesAlgorithm *QgsArrayTranslatedFeaturesAlgorithm::createInstance()
const
74 return new QgsArrayTranslatedFeaturesAlgorithm();
77void QgsArrayTranslatedFeaturesAlgorithm::initParameters(
const QVariantMap & )
80 count->setIsDynamic(
true );
82 count->setDynamicLayerParameterName( u
"INPUT"_s );
83 addParameter( count.release() );
85 auto xOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_X"_s, QObject::tr(
"Step distance (x-axis)" ), 0.0, u
"INPUT"_s );
86 xOffset->setIsDynamic(
true );
88 xOffset->setDynamicLayerParameterName( u
"INPUT"_s );
89 addParameter( xOffset.release() );
91 auto yOffset = std::make_unique<QgsProcessingParameterDistance>( u
"DELTA_Y"_s, QObject::tr(
"Step distance (y-axis)" ), 0.0, u
"INPUT"_s );
92 yOffset->setIsDynamic(
true );
94 yOffset->setDynamicLayerParameterName( u
"INPUT"_s );
95 addParameter( yOffset.release() );
98 zOffset->setIsDynamic(
true );
100 zOffset->setDynamicLayerParameterName( u
"INPUT"_s );
101 addParameter( zOffset.release() );
104 mOffset->setIsDynamic(
true );
106 mOffset->setDynamicLayerParameterName( u
"INPUT"_s );
107 addParameter( mOffset.release() );
112 mCount = parameterAsInt( parameters, u
"COUNT"_s, context );
115 mCountProperty = parameters.value( u
"COUNT"_s ).value<
QgsProperty>();
117 mDeltaX = parameterAsDouble( parameters, u
"DELTA_X"_s, context );
119 if ( mDynamicDeltaX )
120 mDeltaXProperty = parameters.value( u
"DELTA_X"_s ).value<
QgsProperty>();
122 mDeltaY = parameterAsDouble( parameters, u
"DELTA_Y"_s, context );
124 if ( mDynamicDeltaY )
125 mDeltaYProperty = parameters.value( u
"DELTA_Y"_s ).value<
QgsProperty>();
127 mDeltaZ = parameterAsDouble( parameters, u
"DELTA_Z"_s, context );
129 if ( mDynamicDeltaZ )
130 mDeltaZProperty = parameters.value( u
"DELTA_Z"_s ).value<
QgsProperty>();
132 mDeltaM = parameterAsDouble( parameters, u
"DELTA_M"_s, context );
134 if ( mDynamicDeltaM )
135 mDeltaMProperty = parameters.value( u
"DELTA_M"_s ).value<
QgsProperty>();
152 result.reserve( count + 1 );
154 double deltaX = mDeltaX;
155 if ( mDynamicDeltaX )
157 double deltaY = mDeltaY;
158 if ( mDynamicDeltaY )
160 double deltaZ = mDeltaZ;
161 if ( mDynamicDeltaZ )
163 double deltaM = mDeltaM;
164 if ( mDynamicDeltaM )
177 outAttrs << QVariant( 0 );
182 for (
int i = 0; i < count; ++i )
185 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
188 outAttrs << QVariant( i + 1 );
190 result << offsetFeature;
211QgsFields 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