22using namespace Qt::StringLiterals;
26QString QgsCreateArrayOffsetLinesAlgorithm::name()
const
28 return u
"arrayoffsetlines"_s;
31QString QgsCreateArrayOffsetLinesAlgorithm::displayName()
const
33 return QObject::tr(
"Array of offset (parallel) lines" );
36QStringList QgsCreateArrayOffsetLinesAlgorithm::tags()
const
38 return QObject::tr(
"offset,parallel,duplicate,create,spaced,copy,features,objects,step,repeat" ).split(
',' );
41QString QgsCreateArrayOffsetLinesAlgorithm::group()
const
43 return QObject::tr(
"Vector creation" );
46QString QgsCreateArrayOffsetLinesAlgorithm::groupId()
const
48 return u
"vectorcreation"_s;
51QString QgsCreateArrayOffsetLinesAlgorithm::outputName()
const
53 return QObject::tr(
"Offset lines" );
56QString QgsCreateArrayOffsetLinesAlgorithm::shortHelpString()
const
59 "This algorithm creates copies of line features in a layer, by creating multiple offset versions of each feature. "
60 "Each copy is offset by a preset distance."
64QString QgsCreateArrayOffsetLinesAlgorithm::shortDescription()
const
66 return QObject::tr(
"Creates multiple offset copies of lines from a layer." );
74QgsCreateArrayOffsetLinesAlgorithm *QgsCreateArrayOffsetLinesAlgorithm::createInstance()
const
76 return new QgsCreateArrayOffsetLinesAlgorithm();
79void QgsCreateArrayOffsetLinesAlgorithm::initParameters(
const QVariantMap & )
82 count->setIsDynamic(
true );
84 count->setDynamicLayerParameterName( u
"INPUT"_s );
85 addParameter( count.release() );
87 auto offset = std::make_unique<QgsProcessingParameterDistance>( u
"OFFSET"_s, QObject::tr(
"Offset step distance" ), 1.0, u
"INPUT"_s );
88 offset->setIsDynamic(
true );
90 offset->setDynamicLayerParameterName( u
"INPUT"_s );
91 addParameter( offset.release() );
95 addParameter( segmentParam.release() );
98 = std::make_unique<QgsProcessingParameterEnum>( u
"JOIN_STYLE"_s, QObject::tr(
"Join style" ), QStringList() << QObject::tr(
"Round" ) << QObject::tr(
"Miter" ) << QObject::tr(
"Bevel" ),
false, 0 );
100 addParameter( joinStyleParam.release() );
104 addParameter( miterLimitParam.release() );
107QList<int> QgsCreateArrayOffsetLinesAlgorithm::inputLayerTypes()
const
114 mCount = parameterAsInt( parameters, u
"COUNT"_s, context );
117 mCountProperty = parameters.value( u
"COUNT"_s ).value<
QgsProperty>();
119 mOffsetStep = parameterAsDouble( parameters, u
"OFFSET"_s, context );
121 if ( mDynamicOffset )
122 mOffsetStepProperty = parameters.value( u
"OFFSET"_s ).value<
QgsProperty>();
124 mSegments = parameterAsInt( parameters, u
"SEGMENTS"_s, context );
125 mJoinStyle =
static_cast<Qgis::JoinStyle>( 1 + parameterAsInt( parameters, u
"JOIN_STYLE"_s, context ) );
126 mMiterLimit = parameterAsDouble( parameters, u
"MITER_LIMIT"_s, context );
143 result.reserve( count + 1 );
145 double offsetStep = mOffsetStep;
146 if ( mDynamicOffset )
153 outAttrs << QVariant( 0 ) << QVariant( 0 );
159 for (
int i = 0; i < count; ++i )
161 offset += offsetStep;
167 outAttrs << QVariant( i + 1 ) << QVariant( offset );
169 result << offsetFeature;
180QgsFields QgsCreateArrayOffsetLinesAlgorithm::outputFields(
const QgsFields &inputFields )
const
183 newFields.
append(
QgsField( u
"instance"_s, QMetaType::Type::Int ) );
184 newFields.
append(
QgsField( u
"offset"_s, QMetaType::Type::Double ) );
@ VectorLine
Vector line layers.
JoinStyle
Join styles for buffers.
@ 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.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Double
Double/float values.
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.
QgsGeometry offsetCurve(double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit) const
Returns an offset line at a given distance and side from an input line.
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.
QList< QgsFeature > QgsFeatureList