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
58 return QObject::tr(
"This algorithm creates copies of line features in a layer, by creating multiple offset versions of each feature. "
59 "Each copy is offset by a preset distance." );
62QString QgsCreateArrayOffsetLinesAlgorithm::shortDescription()
const
64 return QObject::tr(
"Creates multiple offset copies of lines from a layer." );
72QgsCreateArrayOffsetLinesAlgorithm *QgsCreateArrayOffsetLinesAlgorithm::createInstance()
const
74 return new QgsCreateArrayOffsetLinesAlgorithm();
77void QgsCreateArrayOffsetLinesAlgorithm::initParameters(
const QVariantMap & )
80 count->setIsDynamic(
true );
82 count->setDynamicLayerParameterName( u
"INPUT"_s );
83 addParameter( count.release() );
85 auto offset = std::make_unique<QgsProcessingParameterDistance>( u
"OFFSET"_s, QObject::tr(
"Offset step distance" ), 1.0, u
"INPUT"_s );
86 offset->setIsDynamic(
true );
88 offset->setDynamicLayerParameterName( u
"INPUT"_s );
89 addParameter( offset.release() );
93 addParameter( segmentParam.release() );
95 auto joinStyleParam = std::make_unique<QgsProcessingParameterEnum>( u
"JOIN_STYLE"_s, QObject::tr(
"Join style" ), QStringList() << QObject::tr(
"Round" ) << QObject::tr(
"Miter" ) << QObject::tr(
"Bevel" ),
false, 0 );
97 addParameter( joinStyleParam.release() );
101 addParameter( miterLimitParam.release() );
104QList<int> QgsCreateArrayOffsetLinesAlgorithm::inputLayerTypes()
const
111 mCount = parameterAsInt( parameters, u
"COUNT"_s, context );
114 mCountProperty = parameters.value( u
"COUNT"_s ).value<
QgsProperty>();
116 mOffsetStep = parameterAsDouble( parameters, u
"OFFSET"_s, context );
118 if ( mDynamicOffset )
119 mOffsetStepProperty = parameters.value( u
"OFFSET"_s ).value<
QgsProperty>();
121 mSegments = parameterAsInt( parameters, u
"SEGMENTS"_s, context );
122 mJoinStyle =
static_cast<Qgis::JoinStyle>( 1 + parameterAsInt( parameters, u
"JOIN_STYLE"_s, context ) );
123 mMiterLimit = parameterAsDouble( parameters, u
"MITER_LIMIT"_s, context );
140 result.reserve( count + 1 );
142 double offsetStep = mOffsetStep;
143 if ( mDynamicOffset )
150 outAttrs << QVariant( 0 ) << QVariant( 0 );
156 for (
int i = 0; i < count; ++i )
158 offset += offsetStep;
164 outAttrs << QVariant( i + 1 ) << QVariant( offset );
166 result << offsetFeature;
177QgsFields QgsCreateArrayOffsetLinesAlgorithm::outputFields(
const QgsFields &inputFields )
const
180 newFields.
append(
QgsField( u
"instance"_s, QMetaType::Type::Int ) );
181 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