22QString QgsArrayTranslatedFeaturesAlgorithm::name()
const
24 return QStringLiteral(
"arraytranslatedfeatures" );
27QString QgsArrayTranslatedFeaturesAlgorithm::displayName()
const
29 return QObject::tr(
"Array of translated features" );
32QStringList QgsArrayTranslatedFeaturesAlgorithm::tags()
const
34 return QObject::tr(
"translate,parallel,offset,duplicate,grid,spaced,moved,copy,features,objects,step,repeat" ).split(
',' );
37QString QgsArrayTranslatedFeaturesAlgorithm::group()
const
39 return QObject::tr(
"Vector creation" );
42QString QgsArrayTranslatedFeaturesAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorcreation" );
47QString QgsArrayTranslatedFeaturesAlgorithm::outputName()
const
49 return QObject::tr(
"Translated" );
52QString 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." );
58QString QgsArrayTranslatedFeaturesAlgorithm::shortDescription()
const
60 return QObject::tr(
"Creates multiple translated copies of features in a layer." );
68QgsArrayTranslatedFeaturesAlgorithm *QgsArrayTranslatedFeaturesAlgorithm::createInstance()
const
70 return new QgsArrayTranslatedFeaturesAlgorithm();
73void QgsArrayTranslatedFeaturesAlgorithm::initParameters(
const QVariantMap & )
75 std::unique_ptr<QgsProcessingParameterNumber> count = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"COUNT" ), QObject::tr(
"Number of features to create" ),
Qgis::ProcessingNumberParameterType::Integer, 10,
false, 1 );
76 count->setIsDynamic(
true );
78 count->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
79 addParameter( count.release() );
81 std::unique_ptr<QgsProcessingParameterDistance> xOffset = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DELTA_X" ), QObject::tr(
"Step distance (x-axis)" ), 0.0, QStringLiteral(
"INPUT" ) );
82 xOffset->setIsDynamic(
true );
84 xOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
85 addParameter( xOffset.release() );
87 std::unique_ptr<QgsProcessingParameterDistance> yOffset = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"DELTA_Y" ), QObject::tr(
"Step distance (y-axis)" ), 0.0, QStringLiteral(
"INPUT" ) );
88 yOffset->setIsDynamic(
true );
90 yOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
91 addParameter( yOffset.release() );
93 std::unique_ptr<QgsProcessingParameterNumber> zOffset = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"DELTA_Z" ), QObject::tr(
"Step distance (z-axis)" ),
Qgis::ProcessingNumberParameterType::Double, 0.0 );
94 zOffset->setIsDynamic(
true );
96 zOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
97 addParameter( zOffset.release() );
99 std::unique_ptr<QgsProcessingParameterNumber> mOffset = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"DELTA_M" ), QObject::tr(
"Step distance (m values)" ),
Qgis::ProcessingNumberParameterType::Double, 0.0 );
100 mOffset->setIsDynamic(
true );
102 mOffset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
103 addParameter( mOffset.release() );
108 mCount = parameterAsInt( parameters, QStringLiteral(
"COUNT" ), context );
111 mCountProperty = parameters.value( QStringLiteral(
"COUNT" ) ).value<
QgsProperty>();
113 mDeltaX = parameterAsDouble( parameters, QStringLiteral(
"DELTA_X" ), context );
115 if ( mDynamicDeltaX )
116 mDeltaXProperty = parameters.value( QStringLiteral(
"DELTA_X" ) ).value<
QgsProperty>();
118 mDeltaY = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Y" ), context );
120 if ( mDynamicDeltaY )
121 mDeltaYProperty = parameters.value( QStringLiteral(
"DELTA_Y" ) ).value<
QgsProperty>();
123 mDeltaZ = parameterAsDouble( parameters, QStringLiteral(
"DELTA_Z" ), context );
125 if ( mDynamicDeltaZ )
126 mDeltaZProperty = parameters.value( QStringLiteral(
"DELTA_Z" ) ).value<
QgsProperty>();
128 mDeltaM = parameterAsDouble( parameters, QStringLiteral(
"DELTA_M" ), context );
130 if ( mDynamicDeltaM )
131 mDeltaMProperty = parameters.value( QStringLiteral(
"DELTA_M" ) ).value<
QgsProperty>();
148 result.reserve( count + 1 );
150 double deltaX = mDeltaX;
151 if ( mDynamicDeltaX )
153 double deltaY = mDeltaY;
154 if ( mDynamicDeltaY )
156 double deltaZ = mDeltaZ;
157 if ( mDynamicDeltaZ )
159 double deltaM = mDeltaM;
160 if ( mDynamicDeltaM )
173 outAttrs << QVariant( 0 );
178 for (
int i = 0; i < count; ++i )
181 geometry.
translate( deltaX, deltaY, deltaZ, deltaM );
184 outAttrs << QVariant( i + 1 );
186 result << offsetFeature;
207QgsFields QgsArrayTranslatedFeaturesAlgorithm::outputFields(
const QgsFields &inputFields )
const
210 output.
append(
QgsField( QStringLiteral(
"instance" ), QMetaType::Type::Int ) );
@ 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