25using namespace Qt::StringLiterals;
29QString QgsRemovePartsByLengthAlgorithm::name()
const
31 return u
"removepartsbylength"_s;
34QString QgsRemovePartsByLengthAlgorithm::displayName()
const
36 return QObject::tr(
"Remove parts by length" );
39QStringList QgsRemovePartsByLengthAlgorithm::tags()
const
41 return QObject::tr(
"remove,delete,drop,filter,lines,linestring,polyline,size" ).split(
',' );
44QString QgsRemovePartsByLengthAlgorithm::group()
const
46 return QObject::tr(
"Vector geometry" );
49QString QgsRemovePartsByLengthAlgorithm::groupId()
const
51 return u
"vectorgeometry"_s;
54QString QgsRemovePartsByLengthAlgorithm::outputName()
const
56 return QObject::tr(
"Cleaned" );
59QList<int> QgsRemovePartsByLengthAlgorithm::inputLayerTypes()
const
69QString QgsRemovePartsByLengthAlgorithm::shortDescription()
const
71 return QObject::tr(
"Removes lines which are shorter than a specified length." );
74QString QgsRemovePartsByLengthAlgorithm::shortHelpString()
const
76 return QObject::tr(
"This algorithm takes a line layer and removes lines which are shorter than a specified length.\n\n"
77 "If the input geometry is a multipart geometry, then the parts will be filtered by their individual lengths. If no parts match the "
78 "required minimum length, then the feature will be skipped and omitted from the output layer.\n\n"
79 "If the input geometry is a singlepart geometry, then the feature will be skipped if the geometry's "
80 "length is below the required size and omitted from the output layer.\n\n"
81 "The length will be calculated using Cartesian calculations in the source layer's coordinate reference system.\n\n"
82 "Attributes are not modified." );
85QgsRemovePartsByLengthAlgorithm *QgsRemovePartsByLengthAlgorithm::createInstance()
const
87 return new QgsRemovePartsByLengthAlgorithm();
96void QgsRemovePartsByLengthAlgorithm::initParameters(
const QVariantMap & )
98 auto minLength = std::make_unique< QgsProcessingParameterDistance >( u
"MIN_LENGTH"_s, QObject::tr(
"Remove parts with lengths less than" ), 0.0, u
"INPUT"_s,
false, 0 );
99 minLength->setIsDynamic(
true );
101 minLength->setDynamicLayerParameterName( u
"INPUT"_s );
102 addParameter( minLength.release() );
107 mMinLength = parameterAsDouble( parameters, u
"MIN_LENGTH"_s, context );
109 if ( mDynamicMinLength )
110 mMinLengthProperty = parameters.value( u
"MIN_LENGTH"_s ).value<
QgsProperty >();
120 double minLength = mMinLength;
121 if ( mDynamicMinLength )
122 minLength = mMinLengthProperty.valueAsDouble( context.
expressionContext(), minLength );
128 std::unique_ptr< QgsGeometryCollection > filteredGeometry( inputCollection->createEmptyWithSameType() );
129 const int size = inputCollection->numGeometries();
130 filteredGeometry->reserve( size );
131 for (
int i = 0; i < size; ++i )
135 if ( curve->length() >= minLength )
137 filteredGeometry->addGeometry( curve->clone() );
141 if ( filteredGeometry->numGeometries() == 0 )
146 outputGeometry =
QgsGeometry( std::move( filteredGeometry ) );
151 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