26QString QgsKeepNBiggestPartsAlgorithm::name()
const
28 return QStringLiteral(
"keepnbiggestparts" );
31QString QgsKeepNBiggestPartsAlgorithm::displayName()
const
33 return QObject::tr(
"Keep N biggest parts" );
36QStringList QgsKeepNBiggestPartsAlgorithm::tags()
const
38 return QObject::tr(
"remove,delete,drop,largest,area,filter" ).split(
',' );
41QString QgsKeepNBiggestPartsAlgorithm::group()
const
43 return QObject::tr(
"Vector geometry" );
46QString QgsKeepNBiggestPartsAlgorithm::groupId()
const
48 return QStringLiteral(
"vectorgeometry" );
51QString QgsKeepNBiggestPartsAlgorithm::outputName()
const
53 return QObject::tr(
"Parts" );
56QList<int> QgsKeepNBiggestPartsAlgorithm::inputLayerTypes()
const
66QString QgsKeepNBiggestPartsAlgorithm::shortHelpString()
const
68 return QObject::tr(
"This algorithm takes a polygon layer and creates a new polygon layer in which multipart "
69 "geometries have been removed, leaving only the n largest (in terms of area) parts." );
72QgsKeepNBiggestPartsAlgorithm *QgsKeepNBiggestPartsAlgorithm::createInstance()
const
74 return new QgsKeepNBiggestPartsAlgorithm();
83void QgsKeepNBiggestPartsAlgorithm::initParameters(
const QVariantMap & )
85 std::unique_ptr< QgsProcessingParameterNumber > partsToKeep = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PARTS" ),
88 partsToKeep->setIsDynamic(
true );
90 partsToKeep->setDynamicLayerParameterName( QStringLiteral(
"POLYGONS" ) );
91 addParameter( partsToKeep.release() );
94QString QgsKeepNBiggestPartsAlgorithm::inputParameterName()
const
96 return QStringLiteral(
"POLYGONS" );
101 mPartsToKeep = parameterAsInt( parameters, QStringLiteral(
"PARTS" ), context );
103 if ( mDynamicPartsToKeep )
104 mPartsToKeepProperty = parameters.value( QStringLiteral(
"PARTS" ) ).value<
QgsProperty >();
119 outputGeometry = geometry;
124 int nPartsToKeep = mPartsToKeep;
125 if ( mDynamicPartsToKeep )
126 nPartsToKeep = mPartsToKeepProperty.valueAsInt( context.
expressionContext(), nPartsToKeep );
130 if ( nPartsToKeep >= numParts )
133 outputGeometry = geometry;
137 struct GreaterThanByArea
146 std::priority_queue< const QgsAbstractGeometry *, std::vector<const QgsAbstractGeometry *>, GreaterThanByArea > areaQueue;
147 for (
int i = 0; i < numParts; ++i )
149 areaQueue.push( collection->
geometryN( i ) );
152 for (
int i = 0; i < nPartsToKeep; ++i )
156 res->addGeometry( part->
clone() );
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.
Abstract base class for all geometries.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
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.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
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.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
Multi polygon geometry collection.
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.
@ IntegerPositive
Positive integer values (including 0)
A store for object properties.
static bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
QList< QgsFeature > QgsFeatureList