QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
qgsgeometrygapcheck.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometrygapcheck.cpp
3 ---------------------
4 begin : September 2015
5 copyright : (C) 2014 by Sandro Mani / Sourcepole AG
6 email : smani at sourcepole dot ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgsgeometryengine.h"
18#include "qgsgeometrygapcheck.h"
19#include "qgsfeaturepool.h"
20#include "qgsvectorlayer.h"
21#include "qgsvectorlayerutils.h"
22#include "qgsfeedback.h"
23#include "qgsapplication.h"
24#include "qgsproject.h"
26#include "qgspolygon.h"
27#include "qgscurve.h"
28
29QgsGeometryGapCheck::QgsGeometryGapCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration )
30 : QgsGeometryCheck( context, configuration )
31 , mGapThresholdMapUnits( configuration.value( QStringLiteral( "gapThreshold" ) ).toDouble() )
32{
33}
34
35void QgsGeometryGapCheck::prepare( const QgsGeometryCheckContext *context, const QVariantMap &configuration )
36{
37 if ( configuration.value( QStringLiteral( "allowedGapsEnabled" ) ).toBool() )
38 {
39 QgsVectorLayer *layer = context->project()->mapLayer<QgsVectorLayer *>( configuration.value( "allowedGapsLayer" ).toString() );
40 if ( layer )
41 {
42 mAllowedGapsLayer = layer;
43 mAllowedGapsSource = std::make_unique<QgsVectorLayerFeatureSource>( layer );
44
45 mAllowedGapsBuffer = configuration.value( QStringLiteral( "allowedGapsBuffer" ) ).toDouble();
46 }
47 }
48 else
49 {
50 mAllowedGapsSource.reset();
51 }
52}
53
54void QgsGeometryGapCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
55{
56 if ( feedback )
57 feedback->setProgress( feedback->progress() + 1.0 );
58
59 std::unique_ptr<QgsAbstractGeometry> allowedGapsGeom;
60 std::unique_ptr<QgsGeometryEngine> allowedGapsGeomEngine;
61
62 if ( mAllowedGapsSource )
63 {
64 QVector<QgsGeometry> allowedGaps;
65 QgsFeatureRequest request;
67 QgsFeatureIterator iterator = mAllowedGapsSource->getFeatures( request );
68 QgsFeature feature;
69
70 while ( iterator.nextFeature( feature ) )
71 {
72 const QgsGeometry geom = feature.geometry();
73 const QgsGeometry gg = geom.buffer( mAllowedGapsBuffer, 20 );
74 allowedGaps.append( gg );
75 }
76
77 std::unique_ptr< QgsGeometryEngine > allowedGapsEngine = QgsGeometryCheckerUtils::createGeomEngine( nullptr, mContext->tolerance );
78
79 // Create union of allowed gaps
80 QString errMsg;
81 allowedGapsGeom.reset( allowedGapsEngine->combine( allowedGaps, &errMsg ) );
82 allowedGapsGeomEngine = QgsGeometryCheckerUtils::createGeomEngine( allowedGapsGeom.get(), mContext->tolerance );
83 allowedGapsGeomEngine->prepareGeometry();
84 }
85
86 QVector<QgsGeometry> geomList;
87 const QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
88 const QgsGeometryCheckerUtils::LayerFeatures layerFeatures( featurePools, featureIds, compatibleGeometryTypes(), nullptr, mContext, true );
89 for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
90 {
91 geomList.append( layerFeature.geometry() );
92
93 if ( feedback && feedback->isCanceled() )
94 {
95 geomList.clear();
96 break;
97 }
98 }
99
100 if ( geomList.isEmpty() )
101 {
102 return;
103 }
104
105 std::unique_ptr< QgsGeometryEngine > geomEngine = QgsGeometryCheckerUtils::createGeomEngine( nullptr, mContext->tolerance );
106
107 // Create union of geometry
108 QString errMsg;
109 const std::unique_ptr<QgsAbstractGeometry> unionGeom( geomEngine->combine( geomList, &errMsg ) );
110 if ( !unionGeom )
111 {
112 messages.append( tr( "Gap check: %1" ).arg( errMsg ) );
113 return;
114 }
115
116 // Get envelope of union
117 geomEngine = QgsGeometryCheckerUtils::createGeomEngine( unionGeom.get(), mContext->tolerance );
118 geomEngine->prepareGeometry();
119 std::unique_ptr<QgsAbstractGeometry> envelope( geomEngine->envelope( &errMsg ) );
120 if ( !envelope )
121 {
122 messages.append( tr( "Gap check: %1" ).arg( errMsg ) );
123 return;
124 }
125
126 // Buffer envelope
127 geomEngine = QgsGeometryCheckerUtils::createGeomEngine( envelope.get(), mContext->tolerance );
128 geomEngine->prepareGeometry();
129 QgsAbstractGeometry *bufEnvelope = geomEngine->buffer( 2, 0, Qgis::EndCapStyle::Square, Qgis::JoinStyle::Miter, 4. ); //#spellok //#spellok
130 envelope.reset( bufEnvelope );
131
132 // Compute difference between envelope and union to obtain gap polygons
133 geomEngine = QgsGeometryCheckerUtils::createGeomEngine( envelope.get(), mContext->tolerance );
134 geomEngine->prepareGeometry();
135 std::unique_ptr<QgsAbstractGeometry> diffGeom( geomEngine->difference( unionGeom.get(), &errMsg ) );
136 if ( !diffGeom )
137 {
138 messages.append( tr( "Gap check: %1" ).arg( errMsg ) );
139 return;
140 }
141
142 // For each gap polygon which does not lie on the boundary, get neighboring polygons and add error
143 QgsGeometryPartIterator parts = diffGeom->parts();
144 while ( parts.hasNext() )
145 {
146 const QgsAbstractGeometry *gapGeom = parts.next();
147 // Skip the gap between features and boundingbox
148 const double spacing = context()->tolerance;
149 if ( gapGeom->boundingBox().snappedToGrid( spacing ) == envelope->boundingBox().snappedToGrid( spacing ) )
150 {
151 continue;
152 }
153
154 // Skip gaps above threshold
155 if ( ( mGapThresholdMapUnits > 0 && gapGeom->area() > mGapThresholdMapUnits ) || gapGeom->area() < mContext->reducedTolerance )
156 {
157 continue;
158 }
159
160 QgsRectangle gapAreaBBox = gapGeom->boundingBox();
161
162 // Get neighboring polygons
163 QMap<QString, QgsFeatureIds> neighboringIds;
164 const QgsGeometryCheckerUtils::LayerFeatures layerFeatures( featurePools, featureIds.keys(), gapAreaBBox, compatibleGeometryTypes(), mContext );
165 std::unique_ptr< QgsGeometryEngine > gapGeomEngine = QgsGeometryCheckerUtils::createGeomEngine( gapGeom, mContext->tolerance );
166 gapGeomEngine->prepareGeometry();
167 for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
168 {
169 const QgsGeometry geom = layerFeature.geometry();
170 if ( gapGeomEngine->distance( geom.constGet() ) < mContext->tolerance )
171 {
172 neighboringIds[layerFeature.layer()->id()].insert( layerFeature.feature().id() );
173 gapAreaBBox.combineExtentWith( geom.boundingBox() );
174 }
175 }
176
177 if ( neighboringIds.isEmpty() )
178 {
179 continue;
180 }
181
182 if ( allowedGapsGeomEngine && allowedGapsGeomEngine->contains( gapGeom ) )
183 {
184 continue;
185 }
186
187 // Add error
188 const double area = gapGeom->area();
189 const QgsRectangle gapBbox = gapGeom->boundingBox();
190 errors.append( new QgsGeometryGapCheckError( this, QString(), QgsGeometry( gapGeom->clone() ), neighboringIds, area, gapBbox, gapAreaBBox ) );
191 }
192}
193
194void QgsGeometryGapCheck::fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> & /*mergeAttributeIndices*/, Changes &changes ) const
195{
196 const QMetaEnum metaEnum = QMetaEnum::fromType<QgsGeometryGapCheck::ResolutionMethod>();
197 if ( !metaEnum.isValid() || !metaEnum.valueToKey( method ) )
198 {
199 error->setFixFailed( tr( "Unknown method" ) );
200 }
201 else
202 {
203 const ResolutionMethod methodValue = static_cast<ResolutionMethod>( method );
204 switch ( methodValue )
205 {
206 case NoChange:
207 error->setFixed( method );
208 break;
209
210 case MergeLongestEdge:
211 {
212 QString errMsg;
213 if ( mergeWithNeighbor( featurePools, static_cast<QgsGeometryGapCheckError *>( error ), changes, errMsg, LongestSharedEdge ) )
214 {
215 error->setFixed( method );
216 }
217 else
218 {
219 error->setFixFailed( tr( "Failed to merge with neighbor: %1" ).arg( errMsg ) );
220 }
221 break;
222 }
223
224 case AddToAllowedGaps:
225 {
226 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mAllowedGapsLayer.data() );
227 if ( layer )
228 {
229 if ( !layer->isEditable() && !layer->startEditing() )
230 {
231 error->setFixFailed( tr( "Could not start editing layer %1" ).arg( layer->name() ) );
232 }
233 else
234 {
235 const QgsFeature feature = QgsVectorLayerUtils::createFeature( layer, error->geometry() );
237 if ( !layer->addFeatures( features ) )
238 {
239 error->setFixFailed( tr( "Could not add feature to layer %1" ).arg( layer->name() ) );
240 }
241 else
242 {
243 error->setFixed( method );
244 }
245 }
246 }
247 else
248 {
249 error->setFixFailed( tr( "Allowed gaps layer could not be resolved" ) );
250 }
251 break;
252 }
253
254 case CreateNewFeature:
255 {
256 QgsGeometryGapCheckError *gapCheckError = static_cast<QgsGeometryGapCheckError *>( error );
257 QgsProject *project = QgsProject::instance();
258 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( project->mapLayer( gapCheckError->neighbors().keys().first() ) );
259 if ( layer )
260 {
261 const QgsGeometry geometry = error->geometry();
264 if ( !layer->addFeature( feature ) )
265 {
266 error->setFixFailed( tr( "Could not add feature" ) );
267 }
268 else
269 {
270 error->setFixed( method );
271 }
272 }
273 else
274 {
275 error->setFixFailed( tr( "Could not resolve target layer %1 to add feature" ).arg( error->layerId() ) );
276 }
277 break;
278 }
279
280 case MergeLargestArea:
281 {
282 QString errMsg;
283 if ( mergeWithNeighbor( featurePools, static_cast<QgsGeometryGapCheckError *>( error ), changes, errMsg, LargestArea ) )
284 {
285 error->setFixed( method );
286 }
287 else
288 {
289 error->setFixFailed( tr( "Failed to merge with neighbor: %1" ).arg( errMsg ) );
290 }
291 break;
292 }
293 }
294 }
295}
296
297bool QgsGeometryGapCheck::mergeWithNeighbor( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryGapCheckError *err, Changes &changes, QString &errMsg, Condition condition ) const
298{
299 double maxVal = 0.;
300 QString mergeLayerId;
301 QgsFeature mergeFeature;
302 int mergePartIdx = -1;
303
304 const QgsGeometry geometry = err->geometry();
305 const QgsAbstractGeometry *errGeometry = QgsGeometryCheckerUtils::getGeomPart( geometry.constGet(), 0 );
306
307 const auto layerIds = err->neighbors().keys();
308 QList<QgsFeature> neighbours;
309
310 // Search for touching neighboring geometries
311 for ( const QString &layerId : layerIds )
312 {
313 QgsFeaturePool *featurePool = featurePools.value( layerId );
314 std::unique_ptr<QgsAbstractGeometry> errLayerGeom( errGeometry->clone() );
315 const QgsCoordinateTransform ct( featurePool->crs(), mContext->mapCrs, mContext->transformContext );
316 errLayerGeom->transform( ct, Qgis::TransformDirection::Reverse );
317
318 const auto featureIds = err->neighbors().value( layerId );
319
320 for ( const QgsFeatureId testId : featureIds )
321 {
322 QgsFeature feature;
323 if ( !featurePool->getFeature( testId, feature ) )
324 {
325 continue;
326 }
327
328 QgsGeometry transformedGeometry = feature.geometry();
329 transformedGeometry.transform( ct );
330 feature.setGeometry( transformedGeometry );
331 neighbours.append( feature );
332 }
333
334 for ( const QgsFeature &testFeature : neighbours )
335 {
336 const QgsGeometry featureGeom = testFeature.geometry();
337 const QgsAbstractGeometry *testGeom = featureGeom.constGet();
338 for ( int iPart = 0, nParts = testGeom->partCount(); iPart < nParts; ++iPart )
339 {
340 double val = 0;
341 switch ( condition )
342 {
343 case LongestSharedEdge:
345 break;
346
347 case LargestArea:
348 // We might get a neighbour where we touch only a corner
350 val = QgsGeometryCheckerUtils::getGeomPart( testGeom, iPart )->area();
351 break;
352 }
353
354 if ( val > maxVal )
355 {
356 maxVal = val;
357 mergeFeature = testFeature;
358 mergePartIdx = iPart;
359 mergeLayerId = layerId;
360 }
361 }
362 }
363 }
364
365 if ( maxVal == 0. )
366 {
367 return false;
368 }
369
370 // Create an index of all neighbouring vertices
372 int id = 0;
373 for ( const QgsFeature &neighbour : neighbours )
374 {
375 QgsVertexIterator vit = neighbour.geometry().vertices();
376 while ( vit.hasNext() )
377 {
378 const QgsPoint pt = vit.next();
379 QgsFeature f;
380 f.setId( id ); // required for SpatialIndex to return the correct result
381 f.setGeometry( QgsGeometry( pt.clone() ) );
382 neighbourVerticesIndex.addFeature( f );
383 id++;
384 }
385 }
386
387 // Snap to the closest vertex
388 QgsPolyline snappedRing;
389 QgsVertexIterator iterator = errGeometry->vertices();
390 while ( iterator.hasNext() )
391 {
392 const QgsPoint pt = iterator.next();
393 const QgsGeometry closestGeom = neighbourVerticesIndex.geometry( neighbourVerticesIndex.nearestNeighbor( QgsPointXY( pt ) ).first() );
394 if ( !closestGeom.isEmpty() )
395 {
396 snappedRing.append( QgsPoint( closestGeom.vertexAt( 0 ) ) );
397 }
398 }
399
400 std::unique_ptr<QgsPolygon> snappedErrGeom = std::make_unique<QgsPolygon>();
401 snappedErrGeom->setExteriorRing( new QgsLineString( snappedRing ) );
402
403 // Merge geometries
404 QgsFeaturePool *featurePool = featurePools[ mergeLayerId ];
405 std::unique_ptr<QgsAbstractGeometry> errLayerGeom( snappedErrGeom->clone() );
406 const QgsCoordinateTransform ct( featurePool->crs(), mContext->mapCrs, mContext->transformContext );
407 errLayerGeom->transform( ct, Qgis::TransformDirection::Reverse );
408 const QgsGeometry mergeFeatureGeom = mergeFeature.geometry();
409 const QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.constGet();
410 std::unique_ptr< QgsGeometryEngine > geomEngine = QgsGeometryCheckerUtils::createGeomEngine( errLayerGeom.get(), 0 );
411 std::unique_ptr<QgsAbstractGeometry> combinedGeom( geomEngine->combine( QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), &errMsg ) );
412 if ( !combinedGeom || combinedGeom->isEmpty() || !QgsWkbTypes::isSingleType( combinedGeom->wkbType() ) )
413 {
414 return false;
415 }
416
417 // Add merged polygon to destination geometry
418 replaceFeatureGeometryPart( featurePools, mergeLayerId, mergeFeature, mergePartIdx, combinedGeom.release(), changes );
419
420 return true;
421}
422
423
425{
426 QStringList methods = QStringList()
427 << tr( "Add gap area to neighboring polygon with longest shared edge" )
428 << tr( "No action" );
429 if ( mAllowedGapsSource )
430 methods << tr( "Add gap to allowed exceptions" );
431
432 return methods;
433}
434
435QList<QgsGeometryCheckResolutionMethod> QgsGeometryGapCheck::availableResolutionMethods() const
436{
437 QList<QgsGeometryCheckResolutionMethod> fixes
438 {
439 QgsGeometryCheckResolutionMethod( MergeLongestEdge, tr( "Add to longest shared edge" ), tr( "Add the gap area to the neighbouring polygon with the longest shared edge." ), false ),
440 QgsGeometryCheckResolutionMethod( CreateNewFeature, tr( "Create new feature" ), tr( "Create a new feature from the gap area." ), false ),
441 QgsGeometryCheckResolutionMethod( MergeLargestArea, tr( "Add to largest neighbouring area" ), tr( "Add the gap area to the neighbouring polygon with the largest area." ), false )
442 };
443
444 if ( mAllowedGapsSource )
445 fixes << QgsGeometryCheckResolutionMethod( AddToAllowedGaps, tr( "Add Gap to Allowed Exceptions" ), tr( "Create a new feature from the gap geometry on the allowed exceptions layer." ), true );
446
447 fixes << QgsGeometryCheckResolutionMethod( NoChange, tr( "No action" ), tr( "Do not perform any action and mark this error as fixed." ), false );
448
449 return fixes;
450}
451
453{
454 return factoryDescription();
455}
456
458{
459 return factoryId();
460}
461
463{
464 return factoryFlags();
465}
466
468QString QgsGeometryGapCheck::factoryDescription()
469{
470 return tr( "Gap" );
471}
472
473QString QgsGeometryGapCheck::factoryId()
474{
475 return QStringLiteral( "QgsGeometryGapCheck" );
476}
477
478QgsGeometryCheck::Flags QgsGeometryGapCheck::factoryFlags()
479{
481}
482
483QList<Qgis::GeometryType> QgsGeometryGapCheck::factoryCompatibleGeometryTypes()
484{
486}
487
488bool QgsGeometryGapCheck::factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP
489{
490 return factoryCompatibleGeometryTypes().contains( layer->geometryType() );
491}
492
493QgsGeometryCheck::CheckType QgsGeometryGapCheck::factoryCheckType()
494{
496}
498
500{
501 return mContextBoundingBox;
502}
503
505{
506 QgsGeometryGapCheckError *err = dynamic_cast<QgsGeometryGapCheckError *>( other );
507 return err && err->location().distanceCompare( location(), mCheck->context()->reducedTolerance ) && err->neighbors() == neighbors();
508}
509
511{
512 QgsGeometryGapCheckError *err = dynamic_cast<QgsGeometryGapCheckError *>( other );
513 return err && err->layerId() == layerId() && err->neighbors() == neighbors();
514}
515
517{
519 // Static cast since this should only get called if isEqual == true
520 const QgsGeometryGapCheckError *err = static_cast<const QgsGeometryGapCheckError *>( other );
521 mNeighbors = err->mNeighbors;
522 mGapAreaBBox = err->mGapAreaBBox;
523}
524
529
531{
532 return mGapAreaBBox;
533}
534
535QMap<QString, QgsFeatureIds> QgsGeometryGapCheckError::involvedFeatures() const
536{
537 return mNeighbors;
538}
539
541{
542
544 return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCheckGeometry.svg" ) );
545 else
546 return QgsApplication::getThemeIcon( QStringLiteral( "/checks/SliverOrGap.svg" ) );
547}
@ Polygon
Polygons.
@ Miter
Use mitered joins.
@ Square
Square cap (extends past start/end of line by buffer distance)
@ Reverse
Reverse/inverse transform (from destination to source)
Abstract base class for all geometries.
QgsVertexIterator vertices() const
Returns a read-only, Java-style iterator for traversal of vertices of all the geometry,...
virtual QgsRectangle boundingBox() const
Returns the minimal bounding box for the geometry.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Class for doing transforms between two map coordinate systems.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
A feature pool is based on a vector layer and caches features.
QgsCoordinateReferenceSystem crs() const
The coordinate reference system of this layer.
bool getFeature(QgsFeatureId id, QgsFeature &feature)
Retrieves the feature with the specified id into feature.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
void setId(QgsFeatureId id)
Sets the feature id for this feature.
QgsGeometry geometry
Definition qgsfeature.h:69
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:61
double progress() const
Returns the current progress reported by the feedback object.
Definition qgsfeedback.h:77
Base configuration for geometry checks.
const QgsProject * project() const
The project can be used to resolve additional layers.
const double reducedTolerance
The tolerance to allow for in geometry checks.
const QgsCoordinateTransformContext transformContext
The coordinate transform context with which transformations will be done.
const QgsCoordinateReferenceSystem mapCrs
The coordinate system in which calculations should be done.
const double tolerance
The tolerance to allow for in geometry checks.
This represents an error reported by a geometry check.
@ StatusFixed
The error is fixed.
Status status() const
The status of the error.
virtual void update(const QgsGeometryCheckError *other)
Update this error with the information from other.
const QgsGeometryCheck * mCheck
void setFixed(int method)
Set the status to fixed and specify the method that has been used to fix the error.
void setFixFailed(const QString &reason)
Set the error status to failed and specify the reason for failure.
QgsGeometry geometry() const
The geometry of the error in map units.
const QString & layerId() const
The id of the layer on which this error has been detected.
const QgsPointXY & location() const
The location of the error in map units.
This class implements a resolution for problems detected in geometry checks.
This class implements a geometry check.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
QFlags< Flag > Flags
void replaceFeatureGeometryPart(const QMap< QString, QgsFeaturePool * > &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, QgsAbstractGeometry *newPartGeom, Changes &changes) const
Replaces a part in a feature geometry.
const QgsGeometryCheckContext * mContext
@ AvailableInValidation
This geometry check should be available in layer validation on the vector layer peroperties.
CheckType
The type of a check.
@ LayerCheck
The check controls a whole layer (topology checks)
QMap< QString, QgsFeatureIds > allLayerFeatureIds(const QMap< QString, QgsFeaturePool * > &featurePools) const
Returns all layers and feature ids.
const QgsGeometryCheckContext * context() const
Returns the context.
A layer feature combination to uniquely identify and access a feature in a set of layers.
Contains a set of layers and feature ids in those layers to pass to a geometry check.
static std::unique_ptr< QgsGeometryEngine > createGeomEngine(const QgsAbstractGeometry *geometry, double tolerance)
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
static double sharedEdgeLength(const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol)
An error produced by a QgsGeometryGapCheck.
QgsRectangle contextBoundingBox() const override
The context of the error.
void update(const QgsGeometryCheckError *other) override
Update this error with the information from other.
QMap< QString, QgsFeatureIds > involvedFeatures() const override
Returns a list of involved features.
bool closeMatch(QgsGeometryCheckError *other) const override
Check if this error is almost equal to other.
QIcon icon() const override
Returns an icon that should be shown for this kind of error.
QgsRectangle affectedAreaBBox() const override
The bounding box of the affected area of the error.
bool isEqual(QgsGeometryCheckError *other) const override
Check if this error is equal to other.
bool handleChanges(const QgsGeometryCheck::Changes &) override
Apply a list of changes.
const QMap< QString, QgsFeatureIds > & neighbors() const
A map of layers and feature ids of the neighbors of the gap.
QgsGeometryGapCheck(const QgsGeometryCheckContext *context, const QVariantMap &configuration)
The configuration accepts a "gapThreshold" key which specifies the maximum gap size in squared map un...
void collectErrors(const QMap< QString, QgsFeaturePool * > &featurePools, QList< QgsGeometryCheckError * > &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids=LayerFeatureIds()) const override
The main worker method.
Q_DECL_DEPRECATED QStringList resolutionMethods() const override
Returns a list of descriptions for available resolutions for errors.
QString description() const override
Returns a human readable description for this check.
void fixError(const QMap< QString, QgsFeaturePool * > &featurePools, QgsGeometryCheckError *error, int method, const QMap< QString, int > &mergeAttributeIndices, Changes &changes) const override
Fixes the error error with the specified method.
void prepare(const QgsGeometryCheckContext *context, const QVariantMap &configuration) override
Will be run in the main thread before collectErrors() is called (which may be run from a background t...
QList< QgsGeometryCheckResolutionMethod > availableResolutionMethods() const override
Returns a list of available resolution methods.
QString id() const override
Returns an id for this check.
ResolutionMethod
Resolution methods for geometry gap checks.
@ CreateNewFeature
Create a new feature with the gap geometry.
@ AddToAllowedGaps
Add gap geometry to allowed gaps layer.
@ MergeLongestEdge
Merge the gap with the polygon with the longest shared edge.
@ NoChange
Do not handle the error.
@ MergeLargestArea
Merge with neighbouring polygon with largest area.
QList< Qgis::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
QgsGeometryCheck::Flags flags() const override
Flags for this geometry check.
Java-style iterator for traversal of parts of a geometry.
bool hasNext() const
Find out whether there are more parts.
QgsAbstractGeometry * next()
Returns next part of the geometry (undefined behavior if hasNext() returns false before calling next(...
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Line string geometry type, with support for z-dimension and m-values.
QString name
Definition qgsmaplayer.h:79
A class to represent a 2D point.
Definition qgspointxy.h:60
bool distanceCompare(const QgsPointXY &other, double epsilon=4 *std::numeric_limits< double >::epsilon()) const
Compares this point with another point with a fuzzy tolerance using distance comparison.
Definition qgspointxy.h:269
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
Definition qgspoint.cpp:104
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
A rectangle specified with double values.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
QgsRectangle snappedToGrid(double spacing) const
Returns a copy of this rectangle that is snapped to a grid with the specified spacing between the gri...
A spatial index for QgsFeature objects.
@ FlagStoreFeatureGeometries
Indicates that the spatial index should also store feature geometries. This requires more memory,...
static QgsFeatureList makeFeatureCompatible(const QgsFeature &feature, const QgsVectorLayer *layer, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags())
Converts input feature to be compatible with the given layer.
static QgsFeature createFeature(const QgsVectorLayer *layer, const QgsGeometry &geometry=QgsGeometry(), const QgsAttributeMap &attributes=QgsAttributeMap(), QgsExpressionContext *context=nullptr)
Creates a new feature ready for insertion into a layer.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE bool startEditing()
Makes the layer editable.
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a list of features to the sink.
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a single feature to the sink.
Java-style iterator for traversal of vertices of a geometry.
bool hasNext() const
Find out whether there are more vertices.
QgsPoint next()
Returns next vertex of the geometry (undefined behavior if hasNext() returns false before calling nex...
static bool isSingleType(Qgis::WkbType type)
Returns true if the WKB type is a single type.
#define SIP_SKIP
Definition qgis_sip.h:126
QMap< int, QVariant > QgsAttributeMap
QList< QgsFeature > QgsFeatureList
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
Definition qgsfield.h:27
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
Definition qgsgeometry.h:70
A list of layers and feature ids for each of these layers.
QMap< QString, QgsFeatureIds > toMap() const