25QString QgsRemovePartsByLengthAlgorithm::name()
const
27 return QStringLiteral(
"removepartsbylength" );
30QString QgsRemovePartsByLengthAlgorithm::displayName()
const
32 return QObject::tr(
"Remove parts by length" );
35QStringList QgsRemovePartsByLengthAlgorithm::tags()
const
37 return QObject::tr(
"remove,delete,drop,filter,lines,linestring,polyline,size" ).split(
',' );
40QString QgsRemovePartsByLengthAlgorithm::group()
const
42 return QObject::tr(
"Vector geometry" );
45QString QgsRemovePartsByLengthAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeometry" );
50QString QgsRemovePartsByLengthAlgorithm::outputName()
const
52 return QObject::tr(
"Cleaned" );
55QList<int> QgsRemovePartsByLengthAlgorithm::inputLayerTypes()
const
65QString QgsRemovePartsByLengthAlgorithm::shortDescription()
const
67 return QObject::tr(
"Removes lines which are shorter than a specified length." );
70QString QgsRemovePartsByLengthAlgorithm::shortHelpString()
const
72 return QObject::tr(
"This algorithm takes a line layer and removes lines which are shorter than a specified length.\n\n"
73 "If the input geometry is a multipart geometry, then the parts will be filtered by their individual lengths. If no parts match the "
74 "required minimum length, then the feature will be skipped and omitted from the output layer.\n\n"
75 "If the input geometry is a singlepart geometry, then the feature will be skipped if the geometry's "
76 "length is below the required size and omitted from the output layer.\n\n"
77 "The length will be calculated using Cartesian calculations in the source layer's coordinate reference system.\n\n"
78 "Attributes are not modified." );
81QgsRemovePartsByLengthAlgorithm *QgsRemovePartsByLengthAlgorithm::createInstance()
const
83 return new QgsRemovePartsByLengthAlgorithm();
92void QgsRemovePartsByLengthAlgorithm::initParameters(
const QVariantMap & )
94 auto minLength = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"MIN_LENGTH" ), QObject::tr(
"Remove parts with lengths less than" ), 0.0, QStringLiteral(
"INPUT" ),
false, 0 );
95 minLength->setIsDynamic(
true );
97 minLength->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
98 addParameter( minLength.release() );
103 mMinLength = parameterAsDouble( parameters, QStringLiteral(
"MIN_LENGTH" ), context );
105 if ( mDynamicMinLength )
106 mMinLengthProperty = parameters.value( QStringLiteral(
"MIN_LENGTH" ) ).value<
QgsProperty >();
116 double minLength = mMinLength;
117 if ( mDynamicMinLength )
118 minLength = mMinLengthProperty.valueAsDouble( context.
expressionContext(), minLength );
124 std::unique_ptr< QgsGeometryCollection > filteredGeometry( inputCollection->createEmptyWithSameType() );
125 const int size = inputCollection->numGeometries();
126 filteredGeometry->reserve( size );
127 for (
int i = 0; i < size; ++i )
131 if ( curve->length() >= minLength )
133 filteredGeometry->addGeometry( curve->clone() );
137 if ( filteredGeometry->numGeometries() == 0 )
142 outputGeometry =
QgsGeometry( std::move( filteredGeometry ) );
147 if ( curve->length() < minLength )
ProcessingSourceType
Processing data source types.
@ VectorLine
Vector line layers.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Abstract base class for curved geometry type.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
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...
Definition for a property.
@ DoublePositive
Positive double value (including 0).
A store for object properties.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QList< QgsFeature > QgsFeatureList