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