26QString QgsCoverageSimplifyAlgorithm::name()
const
28 return QStringLiteral(
"coveragesimplify" );
31QString QgsCoverageSimplifyAlgorithm::displayName()
const
33 return QObject::tr(
"Simplify coverage" );
36QStringList QgsCoverageSimplifyAlgorithm::tags()
const
38 return QObject::tr(
"topological,boundary" ).split(
',' );
41QString QgsCoverageSimplifyAlgorithm::group()
const
43 return QObject::tr(
"Vector coverage" );
46QString QgsCoverageSimplifyAlgorithm::groupId()
const
48 return QStringLiteral(
"vectorcoverage" );
51void QgsCoverageSimplifyAlgorithm::initAlgorithm(
const QVariantMap & )
55 QObject::tr(
"Tolerance" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0, 10000000.0 ) );
56 std::unique_ptr< QgsProcessingParameterBoolean > boundaryParameter = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"PRESERVE_BOUNDARY" ), QObject::tr(
"Preserve boundary" ),
false );
57 boundaryParameter->setHelp( QObject::tr(
"When enabled the outside edges of the coverage will be preserved without simplification." ) );
58 addParameter( boundaryParameter.release() );
63QString QgsCoverageSimplifyAlgorithm::shortDescription()
const
65 return QObject::tr(
"Simplifies a coverage of polygon features while retaining valid coverage" );
68QString QgsCoverageSimplifyAlgorithm::shortHelpString()
const
70 return QObject::tr(
"This algorithm operates on a coverage (represented as a set of polygon features "
71 "with exactly matching edge geometry) to apply a Visvalingam–Whyatt "
72 "simplification to the edges, reducing complexity in proportion with "
73 "the provided tolerance, while retaining a valid coverage (i.e. no edges "
74 "will cross or touch after the simplification).\n\n"
75 "Geometries will never be removed, but they may be simplified down to just "
76 "a triangle. Also, some geometries (such as polygons which have too "
77 "few non-repeated points) will be returned unchanged.\n\n"
78 "If the input dataset is not a valid coverage due to overlaps, "
79 "it will still be simplified, but invalid topology such as crossing "
80 "edges will still be invalid." );
83QgsCoverageSimplifyAlgorithm *QgsCoverageSimplifyAlgorithm::createInstance()
const
85 return new QgsCoverageSimplifyAlgorithm();
90 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
94 const bool preserveBoundary = parameterAsBoolean( parameters, QStringLiteral(
"PRESERVE_BOUNDARY" ), context );
95 const double tolerance = parameterAsDouble( parameters, QStringLiteral(
"TOLERANCE" ), context );
98 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, sinkId, source->fields(), source->wkbType(), source->sourceCrs() ) );
103 QVector< QgsFeature > featuresWithGeom;
104 QVector< QgsFeature > featuresWithoutGeom;
107 const long count = source->featureCount();
110 featuresWithGeom.
reserve( count );
114 const double step = count > 0 ? 100.0 / count : 1;
117 feedback->
pushInfo( QObject::tr(
"Collecting features" ) );
130 featuresWithGeom.append( inFeature );
135 featuresWithoutGeom.append( inFeature );
145 switch ( source->invalidGeometryCheck() )
161 feedback->
pushInfo( QObject::tr(
"Simplifying coverage" ) );
163 std::unique_ptr< QgsAbstractGeometry > simplified;
166 simplified =
geos.simplifyCoverageVW( tolerance, preserveBoundary, &error );
175 if ( !error.isEmpty() )
183 feedback->
pushInfo( QObject::tr(
"Storing features" ) );
184 long long featureIndex = 0;
185 for (
auto partsIt = simplified->const_parts_begin(); partsIt != simplified->const_parts_end(); ++partsIt )
187 QgsFeature outFeature = featuresWithGeom.value( featureIndex );
193 feedback->
setProgress( featureIndex * step * 0.2 + 80 );
196 for (
const QgsFeature &feature : featuresWithoutGeom )
206 outputs.insert( QStringLiteral(
"OUTPUT" ), sinkId );
@ VectorPolygon
Vector polygon layers.
@ Valid
Coverage is valid.
@ NoCheck
No invalid geometry checking.
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
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.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
void reserve(int size)
Attempts to allocate memory for at least size geometries.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
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.
Does vector analysis using the geos library and handles import, export, exception handling*.
Custom exception class which is raised when an operation is not supported.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
A double numeric parameter for distance values.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
Contains geos related utilities and functions.