25QString QgsRemovePartsByAreaAlgorithm::name()
const
27 return QStringLiteral(
"removepartsbyarea" );
30QString QgsRemovePartsByAreaAlgorithm::displayName()
const
32 return QObject::tr(
"Remove parts by area" );
35QStringList QgsRemovePartsByAreaAlgorithm::tags()
const
37 return QObject::tr(
"remove,delete,drop,filter,polygon,size" ).split(
',' );
40QString QgsRemovePartsByAreaAlgorithm::group()
const
42 return QObject::tr(
"Vector geometry" );
45QString QgsRemovePartsByAreaAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeometry" );
50QString QgsRemovePartsByAreaAlgorithm::outputName()
const
52 return QObject::tr(
"Cleaned" );
55QList<int> QgsRemovePartsByAreaAlgorithm::inputLayerTypes()
const
65QString QgsRemovePartsByAreaAlgorithm::shortDescription()
const
67 return QObject::tr(
"Removes polygons which are smaller than a specified area." );
70QString QgsRemovePartsByAreaAlgorithm::shortHelpString()
const
72 return QObject::tr(
"This algorithm takes a polygon layer and removes polygons which are smaller than a specified area.\n\n"
73 "If the input geometry is a multipart geometry, then the parts will be filtered by their individual areas. If no parts match the "
74 "required minimum area, 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 "area is below the required size and omitted from the output layer.\n\n"
77 "The area will be calculated using Cartesian calculations in the source layer's coordinate reference system.\n\n"
78 "Attributes are not modified." );
81QgsRemovePartsByAreaAlgorithm *QgsRemovePartsByAreaAlgorithm::createInstance()
const
83 return new QgsRemovePartsByAreaAlgorithm();
92void QgsRemovePartsByAreaAlgorithm::initParameters(
const QVariantMap & )
94 auto minArea = std::make_unique< QgsProcessingParameterArea >( QStringLiteral(
"MIN_AREA" ), QObject::tr(
"Remove parts with area less than" ), 0.0, QStringLiteral(
"INPUT" ),
false, 0 );
95 minArea->setIsDynamic(
true );
97 minArea->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
98 addParameter( minArea.release() );
103 mMinArea = parameterAsDouble( parameters, QStringLiteral(
"MIN_AREA" ), context );
105 if ( mDynamicMinArea )
106 mMinAreaProperty = parameters.value( QStringLiteral(
"MIN_AREA" ) ).value<
QgsProperty >();
116 double minArea = mMinArea;
117 if ( mDynamicMinArea )
118 minArea = mMinAreaProperty.valueAsDouble( context.
expressionContext(), minArea );
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 ( surface->area() >= minArea )
133 filteredGeometry->addGeometry( surface->clone() );
137 if ( filteredGeometry->numGeometries() == 0 )
142 outputGeometry =
QgsGeometry( std::move( filteredGeometry ) );
147 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