QGIS API Documentation 3.38.0-Grenoble (exported)
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< QgsProcessingParameterNumber > minArea = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "MIN_AREA" ),
85 QObject::tr( "Remove holes with area less than" ), Qgis::ProcessingNumberParameterType::Double,
86 0.0, false, 0 );
87 minArea->setIsDynamic( true );
88 minArea->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "MIN_AREA" ), QObject::tr( "Remove holes with area less than" ), QgsPropertyDefinition::DoublePositive ) );
89 minArea->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
90 addParameter( minArea.release() );
91}
92
93bool QgsRemoveHolesAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
94{
95 mMinArea = parameterAsDouble( parameters, QStringLiteral( "MIN_AREA" ), context );
96 mDynamicMinArea = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "MIN_AREA" ) );
97 if ( mDynamicMinArea )
98 mMinAreaProperty = parameters.value( QStringLiteral( "MIN_AREA" ) ).value< QgsProperty >();
99
100 return true;
101}
102
103QgsFeatureList QgsRemoveHolesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback * )
104{
105 QgsFeature f = feature;
106 if ( f.hasGeometry() )
107 {
108 const QgsGeometry geometry = f.geometry();
109
110 double minArea = mMinArea;
111 if ( mDynamicMinArea )
112 minArea = mMinAreaProperty.valueAsDouble( context.expressionContext(), minArea );
113
114 f.setGeometry( geometry.removeInteriorRings( minArea > 0 ? minArea : -1 ) );
115 }
116 return QgsFeatureList() << f;
117}
118
119
121
122
ProcessingSourceType
Processing data source types.
Definition qgis.h:2995
@ 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:3148
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