28using namespace Qt::StringLiterals;
32QString QgsSplitLinesByLengthAlgorithm::name()
const
34 return u
"splitlinesbylength"_s;
37QString QgsSplitLinesByLengthAlgorithm::displayName()
const
39 return QObject::tr(
"Split lines by maximum length" );
42QStringList QgsSplitLinesByLengthAlgorithm::tags()
const
44 return QObject::tr(
"segments,parts,distance,cut,chop" ).split(
',' );
47QString QgsSplitLinesByLengthAlgorithm::group()
const
49 return QObject::tr(
"Vector geometry" );
52QString QgsSplitLinesByLengthAlgorithm::groupId()
const
54 return u
"vectorgeometry"_s;
57QString QgsSplitLinesByLengthAlgorithm::shortHelpString()
const
59 return QObject::tr(
"This algorithm takes a line (or curve) layer and splits each feature into multiple parts, "
60 "where each part is of a specified maximum length.\n\n"
61 "Z and M values at the start and end of the new line substrings are linearly interpolated from existing values." );
64QString QgsSplitLinesByLengthAlgorithm::shortDescription()
const
66 return QObject::tr(
"Splits lines into parts which are not longer than a specified length." );
74QList<int> QgsSplitLinesByLengthAlgorithm::inputLayerTypes()
const
84QgsSplitLinesByLengthAlgorithm *QgsSplitLinesByLengthAlgorithm::createInstance()
const
86 return new QgsSplitLinesByLengthAlgorithm();
89void QgsSplitLinesByLengthAlgorithm::initParameters(
const QVariantMap & )
91 auto length = std::make_unique<QgsProcessingParameterDistance>( u
"LENGTH"_s, QObject::tr(
"Maximum line length" ), 10, u
"INPUT"_s,
false, 0 );
92 length->setIsDynamic(
true );
94 length->setDynamicLayerParameterName( u
"INPUT"_s );
95 addParameter( length.release() );
100 mLength = parameterAsDouble( parameters, u
"LENGTH"_s, context );
102 if ( mDynamicLength )
103 mLengthProperty = parameters.value( u
"LENGTH"_s ).value<
QgsProperty>();
108QString QgsSplitLinesByLengthAlgorithm::outputName()
const
110 return QObject::tr(
"Split" );
118QgsFields QgsSplitLinesByLengthAlgorithm::outputFields(
const QgsFields &inputFields )
const
133 double distance = mLength;
134 if ( mDynamicLength )
135 distance = mLengthProperty.valueAsDouble( context.
expressionContext(), distance );
148 double end = distance;
149 const double length = part->
length();
150 while ( start < length )
157 features << outputFeature;
ProcessingSourceType
Processing data source types.
@ VectorLine
Vector line layers.
@ 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.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
WkbType
The WKB type describes the number of dimensions a geometry has.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
Abstract base class for curved geometry type.
virtual QgsCurve * curveSubstring(double startDistance, double endDistance) const =0
Returns a new curve representing a substring of this curve.
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::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
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.
@ DoublePositive
Positive double value (including 0).
A store for object properties.
static Qgis::WkbType singleType(Qgis::WkbType type)
Returns the single type for a WKB type.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QList< QgsFeature > QgsFeatureList