QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsalgorithmremoveholes.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmremoveholes.cpp
3 ---------------------
4 begin : March 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
21
22QString QgsRemoveHolesAlgorithm::name() const
23{
24 return QStringLiteral( "deleteholes" );
25}
26
27QString QgsRemoveHolesAlgorithm::displayName() const
28{
29 return QObject::tr( "Delete holes" );
30}
31
32QStringList QgsRemoveHolesAlgorithm::tags() const
33{
34 return QObject::tr( "remove,delete,drop,holes,rings,fill" ).split( ',' );
35}
36
37QString QgsRemoveHolesAlgorithm::group() const
38{
39 return QObject::tr( "Vector geometry" );
40}
41
42QString QgsRemoveHolesAlgorithm::groupId() const
43{
44 return QStringLiteral( "vectorgeometry" );
45}
46
47QString QgsRemoveHolesAlgorithm::outputName() const
48{
49 return QObject::tr( "Cleaned" );
50}
51
52QList<int> QgsRemoveHolesAlgorithm::inputLayerTypes() const
53{
54 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
55}
56
57Qgis::ProcessingSourceType QgsRemoveHolesAlgorithm::outputLayerType() const
58{
60}
61
62QString QgsRemoveHolesAlgorithm::shortHelpString() const
63{
64 return QObject::tr( "This algorithm takes a polygon layer and removes holes in polygons. It creates a new vector "
65 "layer in which polygons with holes have been replaced by polygons with only their external ring. "
66 "Attributes are not modified.\n\n"
67 "An optional minimum area parameter allows removing only holes which are smaller than a specified "
68 "area threshold. Leaving this parameter as 0.0 results in all holes being removed." );
69}
70
71QgsRemoveHolesAlgorithm *QgsRemoveHolesAlgorithm::createInstance() const
72{
73 return new QgsRemoveHolesAlgorithm();
74}
75
76Qgis::ProcessingFeatureSourceFlags QgsRemoveHolesAlgorithm::sourceFlags() const
77{
78 // skip geometry checks - this algorithm can be used to repair geometries
80}
81
82void QgsRemoveHolesAlgorithm::initParameters( const QVariantMap & )
83{
84 std::unique_ptr<QgsProcessingParameterArea> minArea = std::make_unique<QgsProcessingParameterArea>( QStringLiteral( "MIN_AREA" ), QObject::tr( "Remove holes with area less than" ), 0.0, QStringLiteral( "INPUT" ), false, 0 );
85 minArea->setIsDynamic( true );
86 minArea->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "MIN_AREA" ), QObject::tr( "Remove holes with area less than" ), QgsPropertyDefinition::DoublePositive ) );
87 minArea->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
88 addParameter( minArea.release() );
89}
90
91bool QgsRemoveHolesAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
92{
93 mMinArea = parameterAsDouble( parameters, QStringLiteral( "MIN_AREA" ), context );
94 mDynamicMinArea = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "MIN_AREA" ) );
95 if ( mDynamicMinArea )
96 mMinAreaProperty = parameters.value( QStringLiteral( "MIN_AREA" ) ).value<QgsProperty>();
97
98 return true;
99}
100
101QgsFeatureList QgsRemoveHolesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback * )
102{
103 QgsFeature f = feature;
104 if ( f.hasGeometry() )
105 {
106 const QgsGeometry geometry = f.geometry();
107
108 double minArea = mMinArea;
109 if ( mDynamicMinArea )
110 minArea = mMinAreaProperty.valueAsDouble( context.expressionContext(), minArea );
111
112 f.setGeometry( geometry.removeInteriorRings( minArea > 0 ? minArea : -1 ) );
113 }
114 return QgsFeatureList() << f;
115}
116
117
ProcessingSourceType
Processing data source types.
Definition qgis.h:3333
@ 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.
Definition qgis.h:3507
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QgsGeometry geometry
Definition qgsfeature.h:69
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.
QgsGeometry removeInteriorRings(double minimumAllowedArea=-1) const
Removes the interior rings from a (multi)polygon geometry.
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 &parameters, 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.
Definition qgsproperty.h:45
@ DoublePositive
Positive double value (including 0)
Definition qgsproperty.h:56
A store for object properties.
QList< QgsFeature > QgsFeatureList