28QString QgsKeepNBiggestPartsAlgorithm::name()
const
30 return QStringLiteral(
"keepnbiggestparts" );
33QString QgsKeepNBiggestPartsAlgorithm::displayName()
const
35 return QObject::tr(
"Keep N biggest parts" );
38QStringList QgsKeepNBiggestPartsAlgorithm::tags()
const
40 return QObject::tr(
"remove,delete,drop,largest,area,filter" ).split(
',' );
43QString QgsKeepNBiggestPartsAlgorithm::group()
const
45 return QObject::tr(
"Vector geometry" );
48QString QgsKeepNBiggestPartsAlgorithm::groupId()
const
50 return QStringLiteral(
"vectorgeometry" );
53QString QgsKeepNBiggestPartsAlgorithm::outputName()
const
55 return QObject::tr(
"Parts" );
58QList<int> QgsKeepNBiggestPartsAlgorithm::inputLayerTypes()
const
68QString QgsKeepNBiggestPartsAlgorithm::shortHelpString()
const
70 return QObject::tr(
"This algorithm takes a polygon layer and creates a new polygon layer in which multipart "
71 "geometries have been removed, leaving only the n largest (in terms of area) parts." );
74QString QgsKeepNBiggestPartsAlgorithm::shortDescription()
const
76 return QObject::tr(
"Creates a polygon layer in which multipart geometries have been removed, "
77 "leaving only the n largest (in terms of area) parts." );
80QgsKeepNBiggestPartsAlgorithm *QgsKeepNBiggestPartsAlgorithm::createInstance()
const
82 return new QgsKeepNBiggestPartsAlgorithm();
91void QgsKeepNBiggestPartsAlgorithm::initParameters(
const QVariantMap & )
94 partsToKeep->setIsDynamic(
true );
96 partsToKeep->setDynamicLayerParameterName( QStringLiteral(
"POLYGONS" ) );
97 addParameter( partsToKeep.release() );
100QString QgsKeepNBiggestPartsAlgorithm::inputParameterName()
const
102 return QStringLiteral(
"POLYGONS" );
107 mPartsToKeep = parameterAsInt( parameters, QStringLiteral(
"PARTS" ), context );
109 if ( mDynamicPartsToKeep )
110 mPartsToKeepProperty = parameters.value( QStringLiteral(
"PARTS" ) ).value<
QgsProperty>();
126 int nPartsToKeep = mPartsToKeep;
127 if ( mDynamicPartsToKeep )
128 nPartsToKeep = mPartsToKeepProperty.valueAsInt( context.
expressionContext(), nPartsToKeep );
130 const int numParts = collection->numGeometries();
131 if ( nPartsToKeep >= numParts )
134 outputGeometry = geometry;
138 struct GreaterThanByArea
140 bool operator()(
const QgsAbstractGeometry *lhs,
const QgsAbstractGeometry *rhs )
const
147 std::priority_queue<const QgsAbstractGeometry *, std::vector<const QgsAbstractGeometry *>, GreaterThanByArea> areaQueue;
148 for (
int i = 0; i < numParts; ++i )
150 areaQueue.push( collection->geometryN( i ) );
153 for (
int i = 0; i < nPartsToKeep; ++i )
157 res->addGeometry( part->
clone() );
165 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