27using namespace Qt::StringLiterals;
31QString QgsKeepNBiggestPartsAlgorithm::name()
const
33 return u
"keepnbiggestparts"_s;
36QString QgsKeepNBiggestPartsAlgorithm::displayName()
const
38 return QObject::tr(
"Keep N biggest parts" );
41QStringList QgsKeepNBiggestPartsAlgorithm::tags()
const
43 return QObject::tr(
"remove,delete,drop,largest,area,filter" ).split(
',' );
46QString QgsKeepNBiggestPartsAlgorithm::group()
const
48 return QObject::tr(
"Vector geometry" );
51QString QgsKeepNBiggestPartsAlgorithm::groupId()
const
53 return u
"vectorgeometry"_s;
56QString QgsKeepNBiggestPartsAlgorithm::outputName()
const
58 return QObject::tr(
"Parts" );
61QList<int> QgsKeepNBiggestPartsAlgorithm::inputLayerTypes()
const
71QString QgsKeepNBiggestPartsAlgorithm::shortHelpString()
const
73 return QObject::tr(
"This algorithm takes a polygon layer and creates a new polygon layer in which multipart "
74 "geometries have been removed, leaving only the n largest (in terms of area) parts." );
77QString QgsKeepNBiggestPartsAlgorithm::shortDescription()
const
79 return QObject::tr(
"Creates a polygon layer in which multipart geometries have been removed, "
80 "leaving only the n largest (in terms of area) parts." );
83QgsKeepNBiggestPartsAlgorithm *QgsKeepNBiggestPartsAlgorithm::createInstance()
const
85 return new QgsKeepNBiggestPartsAlgorithm();
94void QgsKeepNBiggestPartsAlgorithm::initParameters(
const QVariantMap & )
97 partsToKeep->setIsDynamic(
true );
99 partsToKeep->setDynamicLayerParameterName( u
"POLYGONS"_s );
100 addParameter( partsToKeep.release() );
103QString QgsKeepNBiggestPartsAlgorithm::inputParameterName()
const
105 return u
"POLYGONS"_s;
110 mPartsToKeep = parameterAsInt( parameters, u
"PARTS"_s, context );
112 if ( mDynamicPartsToKeep )
113 mPartsToKeepProperty = parameters.value( u
"PARTS"_s ).value<
QgsProperty>();
129 int nPartsToKeep = mPartsToKeep;
130 if ( mDynamicPartsToKeep )
131 nPartsToKeep = mPartsToKeepProperty.valueAsInt( context.
expressionContext(), nPartsToKeep );
133 const int numParts = collection->numGeometries();
134 if ( nPartsToKeep >= numParts )
137 outputGeometry = geometry;
141 struct GreaterThanByArea
143 bool operator()(
const QgsAbstractGeometry *lhs,
const QgsAbstractGeometry *rhs )
const
150 std::priority_queue<const QgsAbstractGeometry *, std::vector<const QgsAbstractGeometry *>, GreaterThanByArea> areaQueue;
151 for (
int i = 0; i < numParts; ++i )
153 areaQueue.push( collection->geometryN( i ) );
156 for (
int i = 0; i < nPartsToKeep; ++i )
160 res->addGeometry( part->
clone() );
168 outputGeometry = geometry;
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.
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.
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 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 Q_INVOKABLE bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QList< QgsFeature > QgsFeatureList