25using namespace Qt::StringLiterals;
29QString QgsRemovePartsByAreaAlgorithm::name()
const
31 return u
"removepartsbyarea"_s;
34QString QgsRemovePartsByAreaAlgorithm::displayName()
const
36 return QObject::tr(
"Remove parts by area" );
39QStringList QgsRemovePartsByAreaAlgorithm::tags()
const
41 return QObject::tr(
"remove,delete,drop,filter,polygon,size" ).split(
',' );
44QString QgsRemovePartsByAreaAlgorithm::group()
const
46 return QObject::tr(
"Vector geometry" );
49QString QgsRemovePartsByAreaAlgorithm::groupId()
const
51 return u
"vectorgeometry"_s;
54QString QgsRemovePartsByAreaAlgorithm::outputName()
const
56 return QObject::tr(
"Cleaned" );
59QList<int> QgsRemovePartsByAreaAlgorithm::inputLayerTypes()
const
69QString QgsRemovePartsByAreaAlgorithm::shortDescription()
const
71 return QObject::tr(
"Removes polygons which are smaller than a specified area." );
74QString QgsRemovePartsByAreaAlgorithm::shortHelpString()
const
77 "This algorithm takes a polygon layer and removes polygons which are smaller than a specified area.\n\n"
78 "If the input geometry is a multipart geometry, then the parts will be filtered by their individual areas. If no parts match the "
79 "required minimum area, then the feature will be skipped and omitted from the output layer.\n\n"
80 "If the input geometry is a singlepart geometry, then the feature will be skipped if the geometry's "
81 "area is below the required size and omitted from the output layer.\n\n"
82 "The area will be calculated using Cartesian calculations in the source layer's coordinate reference system.\n\n"
83 "Attributes are not modified."
87QgsRemovePartsByAreaAlgorithm *QgsRemovePartsByAreaAlgorithm::createInstance()
const
89 return new QgsRemovePartsByAreaAlgorithm();
98void QgsRemovePartsByAreaAlgorithm::initParameters(
const QVariantMap & )
100 auto minArea = std::make_unique< QgsProcessingParameterArea >( u
"MIN_AREA"_s, QObject::tr(
"Remove parts with area less than" ), 0.0, u
"INPUT"_s,
false, 0 );
101 minArea->setIsDynamic(
true );
103 minArea->setDynamicLayerParameterName( u
"INPUT"_s );
104 addParameter( minArea.release() );
109 mMinArea = parameterAsDouble( parameters, u
"MIN_AREA"_s, context );
111 if ( mDynamicMinArea )
112 mMinAreaProperty = parameters.value( u
"MIN_AREA"_s ).value<
QgsProperty >();
119 QGS_MARK_ALGORITHM_SOURCE
122 if ( f.hasGeometry() )
124 double minArea = mMinArea;
125 if ( mDynamicMinArea )
126 minArea = mMinAreaProperty.valueAsDouble( context.
expressionContext(), minArea );
132 std::unique_ptr< QgsGeometryCollection> filteredGeometry( inputCollection->createEmptyWithSameType() );
133 const int size = inputCollection->numGeometries();
134 filteredGeometry->reserve( size );
135 for (
int i = 0; i < size; ++i )
139 if ( surface->area() >= minArea )
141 filteredGeometry->addGeometry( surface->clone() );
145 if ( filteredGeometry->numGeometries() == 0 )
150 outputGeometry =
QgsGeometry( std::move( filteredGeometry ) );
151 f.setGeometry( outputGeometry );
155 if ( surface->area() < minArea )
ProcessingSourceType
Processing data source types.
@ VectorPolygon
Vector polygon 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.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
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