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
76 return QObject::tr(
"This algorithm takes a polygon layer and removes polygons which are smaller than a specified area.\n\n"
77 "If the input geometry is a multipart geometry, then the parts will be filtered by their individual areas. If no parts match the "
78 "required minimum area, 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 "area is below the required size and omitted from the output layer.\n\n"
81 "The area will be calculated using Cartesian calculations in the source layer's coordinate reference system.\n\n"
82 "Attributes are not modified." );
85QgsRemovePartsByAreaAlgorithm *QgsRemovePartsByAreaAlgorithm::createInstance()
const
87 return new QgsRemovePartsByAreaAlgorithm();
96void QgsRemovePartsByAreaAlgorithm::initParameters(
const QVariantMap & )
98 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 );
99 minArea->setIsDynamic(
true );
101 minArea->setDynamicLayerParameterName( u
"INPUT"_s );
102 addParameter( minArea.release() );
107 mMinArea = parameterAsDouble( parameters, u
"MIN_AREA"_s, context );
109 if ( mDynamicMinArea )
110 mMinAreaProperty = parameters.value( u
"MIN_AREA"_s ).value<
QgsProperty >();
120 double minArea = mMinArea;
121 if ( mDynamicMinArea )
122 minArea = mMinAreaProperty.valueAsDouble( context.
expressionContext(), minArea );
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 ( surface->area() >= minArea )
137 filteredGeometry->addGeometry( surface->clone() );
141 if ( filteredGeometry->numGeometries() == 0 )
146 outputGeometry =
QgsGeometry( std::move( filteredGeometry ) );
151 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...
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