27using namespace Qt::StringLiterals;
31QString QgsCoverageValidateAlgorithm::name()
const
33 return u
"coveragevalidate"_s;
36QString QgsCoverageValidateAlgorithm::displayName()
const
38 return QObject::tr(
"Validate coverage" );
41QStringList QgsCoverageValidateAlgorithm::tags()
const
43 return QObject::tr(
"validity,overlaps,gaps,topological,boundary" ).split(
',' );
46QString QgsCoverageValidateAlgorithm::group()
const
48 return QObject::tr(
"Vector coverage" );
51QString QgsCoverageValidateAlgorithm::groupId()
const
53 return u
"vectorcoverage"_s;
56void QgsCoverageValidateAlgorithm::initAlgorithm(
const QVariantMap & )
59 auto gapWidthParam = std::make_unique<QgsProcessingParameterDistance>( u
"GAP_WIDTH"_s, QObject::tr(
"Gap width" ), 0.0, u
"INPUT"_s,
false, 0, 10000000.0 );
60 gapWidthParam->setHelp( QObject::tr(
"The maximum width of gaps to detect" ) );
61 addParameter( gapWidthParam.release() );
67QString QgsCoverageValidateAlgorithm::shortDescription()
const
69 return QObject::tr(
"Analyzes a coverage of polygon features to find places where the assumption of exactly matching edges is not met." );
72QString QgsCoverageValidateAlgorithm::shortHelpString()
const
74 return QObject::tr(
"This algorithm analyzes a coverage (represented as a set of polygon features "
75 "with exactly matching edge geometry) to find places where the "
76 "assumption of exactly matching edges is not met.\n\n"
77 "Invalidity includes polygons that overlap "
78 "or that have gaps smaller than the specified gap width." );
81QgsCoverageValidateAlgorithm *QgsCoverageValidateAlgorithm::createInstance()
const
83 return new QgsCoverageValidateAlgorithm();
88 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, u
"INPUT"_s, context ) );
92 const double gapWidth = parameterAsDouble( parameters, u
"GAP_WIDTH"_s, context );
95 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"INVALID_EDGES"_s, context, sinkId,
QgsFields(),
Qgis::WkbType::LineString, source->sourceCrs() ) );
96 if ( !sink && parameters.value( u
"INVALID_EDGES"_s ).isValid() )
101 const long count = source->featureCount();
107 const double step = count > 0 ? 100.0 / count : 1;
110 feedback->
pushInfo( QObject::tr(
"Collecting features" ) );
130 feedback->
pushInfo( QObject::tr(
"Validating coverage" ) );
134 std::unique_ptr<QgsAbstractGeometry> invalidEdges;
138 result =
geos.validateCoverage( gapWidth, &invalidEdges, &error );
148 feedback->
reportError( QObject::tr(
"Coverage is not valid" ) );
153 for (
auto partsIt = invalidEdges->const_parts_begin(); partsIt != invalidEdges->const_parts_end(); ++partsIt )
164 feedback->
pushInfo( QObject::tr(
"Coverage is valid" ) );
167 if ( !error.isEmpty() )
178 outputs.insert( u
"OUTPUT"_s, sinkId );
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
CoverageValidityResult
Coverage validity results.
@ Valid
Coverage is valid.
@ Invalid
Coverage is invalid. Invalidity includes polygons that overlap, that have gaps smaller than the gap w...
@ Error
An exception occurred while determining validity.
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.
Container of fields for a vector layer.
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, and 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.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
A boolean output for processing algorithms.
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.