27QString QgsCoverageValidateAlgorithm::name()
const
29 return QStringLiteral(
"coveragevalidate" );
32QString QgsCoverageValidateAlgorithm::displayName()
const
34 return QObject::tr(
"Validate coverage" );
37QStringList QgsCoverageValidateAlgorithm::tags()
const
39 return QObject::tr(
"validity,overlaps,gaps,topological,boundary" ).split(
',' );
42QString QgsCoverageValidateAlgorithm::group()
const
44 return QObject::tr(
"Vector coverage" );
47QString QgsCoverageValidateAlgorithm::groupId()
const
49 return QStringLiteral(
"vectorcoverage" );
52void QgsCoverageValidateAlgorithm::initAlgorithm(
const QVariantMap & )
55 std::unique_ptr<QgsProcessingParameterDistance> gapWidthParam = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"GAP_WIDTH" ), QObject::tr(
"Gap width" ), 0.0, QStringLiteral(
"INPUT" ),
false, 0, 10000000.0 );
56 gapWidthParam->setHelp( QObject::tr(
"The maximum width of gaps to detect" ) );
57 addParameter( gapWidthParam.release() );
63QString QgsCoverageValidateAlgorithm::shortDescription()
const
65 return QObject::tr(
"Analyzes a coverage of polygon features to find places where the assumption of exactly matching edges is not met" );
68QString QgsCoverageValidateAlgorithm::shortHelpString()
const
70 return QObject::tr(
"This algorithm analyzes a coverage (represented as a set of polygon features "
71 "with exactly matching edge geometry) to find places where the "
72 "assumption of exactly matching edges is not met.\n\n"
73 "Invalidity includes polygons that overlap "
74 "or that have gaps smaller than the specified gap width." );
77QgsCoverageValidateAlgorithm *QgsCoverageValidateAlgorithm::createInstance()
const
79 return new QgsCoverageValidateAlgorithm();
84 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
88 const double gapWidth = parameterAsDouble( parameters, QStringLiteral(
"GAP_WIDTH" ), context );
91 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"INVALID_EDGES" ), context, sinkId,
QgsFields(),
Qgis::WkbType::LineString, source->sourceCrs() ) );
92 if ( !sink && parameters.value( QStringLiteral(
"INVALID_EDGES" ) ).isValid() )
97 const long count = source->featureCount();
103 const double step = count > 0 ? 100.0 / count : 1;
106 feedback->
pushInfo( QObject::tr(
"Collecting features" ) );
126 feedback->
pushInfo( QObject::tr(
"Validating coverage" ) );
130 std::unique_ptr<QgsAbstractGeometry> invalidEdges;
134 result =
geos.validateCoverage( gapWidth, &invalidEdges, &error );
144 feedback->
reportError( QObject::tr(
"Coverage is not valid" ) );
149 for (
auto partsIt = invalidEdges->const_parts_begin(); partsIt != invalidEdges->const_parts_end(); ++partsIt )
160 feedback->
pushInfo( QObject::tr(
"Coverage is valid" ) );
163 if ( !error.isEmpty() )
174 outputs.insert( QStringLiteral(
"OUTPUT" ), 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.