29#include "moc_qgsgeometrymissingvertexcheck.cpp"
31using namespace Qt::StringLiterals;
44 QMap<QString, QSet<QVariant>> uniqueIds;
46 QgsFeaturePool *featurePool = featurePools.value( featureIds.firstKey() );
49 QgsDebugError( u
"Could not retrieve feature pool for %1"_s.arg( featureIds.firstKey() ) );
60 if (
context()->uniqueIdFieldIndex != -1 )
69 const QgsGeometry geometry = layerFeature.geometry();
74 processPolygon( polygon, featurePool, errors, layerFeature, feedback );
78 const int numGeometries = collection->numGeometries();
79 for (
int i = 0; i < numGeometries; ++i )
83 processPolygon( polygon, featurePool, errors, layerFeature, feedback );
93 Q_UNUSED( featurePools )
96 QMetaEnum metaEnum = QMetaEnum::fromType<QgsGeometryMissingVertexCheck::ResolutionMethod>();
97 if ( !metaEnum.isValid() || !metaEnum.valueToKey( method ) )
104 switch ( methodValue )
136 static QStringList methods = QStringList()
138 << tr(
"Add missing vertex" );
144 return factoryDescription();
150 auto boundaries = std::make_unique<QgsMultiPolygon>();
156 for (
int i = 0; i < numRings; ++i )
163 geomEngine->prepareGeometry();
167 QgsFeature compareFeature;
170 if ( fid == currentFeature.
id() )
173 if ( featurePool->
getFeature( fid, compareFeature ) )
178 const QgsGeometry compareGeometry = compareFeature.
geometry();
179 QgsVertexIterator vertexIterator = compareGeometry.
vertices();
180 while ( vertexIterator.
hasNext() )
182 const QgsPoint &pt = vertexIterator.
next();
183 if ( geomEngine->intersects( &pt ) )
185 QgsVertexId vertexId;
190 bool alreadyReported =
false;
191 for ( QgsGeometryCheckError *error : std::as_const( errors ) )
194 if ( error->featureId() == currentFeature.
id() && error->location() == QgsPointXY( pt ) )
196 alreadyReported =
true;
200 if ( !alreadyReported )
202 auto error = std::make_unique<QgsGeometryMissingVertexCheckError>(
this, layerFeature, QgsPointXY( pt ) );
203 error->setAffectedAreaBBox( contextBoundingBox( polygon, vertexId, pt ) );
204 QMap<QString, QgsFeatureIds> involvedFeatures;
205 involvedFeatures[layerFeature.
layerId()].insert( layerFeature.
feature().
id() );
206 involvedFeatures[featurePool->
layerId()].insert( fid );
207 error->setInvolvedFeatures( involvedFeatures );
209 errors.append( error.release() );
220 QgsVertexId vertexBefore;
221 QgsVertexId vertexAfter;
225 QgsPoint ptBefore = polygon->
vertexAt( vertexBefore );
226 QgsPoint ptAt = polygon->
vertexAt( vertexId );
227 QgsPoint ptAfter = polygon->
vertexAt( vertexAfter );
229 double length = std::abs( ptAt.
distance( ptBefore ) ) + std::abs( ptAt.
distance( ptAfter ) );
231 QgsRectangle rect( point.
x() - length / 2, point.
y() - length / 2, point.
x() + length / 2, point.
y() + length / 2 );
242 return factoryCompatibleGeometryTypes();
247 return factoryFlags();
252 return factoryCheckType();
256QList<Qgis::GeometryType> QgsGeometryMissingVertexCheck::factoryCompatibleGeometryTypes()
263 return factoryCompatibleGeometryTypes().contains( layer->geometryType() );
266QString QgsGeometryMissingVertexCheck::factoryDescription()
268 return tr(
"Missing Vertex" );
271QString QgsGeometryMissingVertexCheck::factoryId()
273 return u
"QgsGeometryMissingVertexCheck"_s;
294 return mAffectedAreaBBox;
304 return mInvolvedFeatures;
Abstract base class for all geometries.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Curve polygon geometry type.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
QgsPoint vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
A feature pool is based on a vector layer and caches features.
virtual void updateFeature(QgsFeature &feature)=0
Updates a feature in this pool.
QString layerId() const
The layer id of the layer.
QgsFeatureIds getIntersects(const QgsRectangle &rect) const
Gets all feature ids in the bounding box rect.
bool getFeature(QgsFeatureId id, QgsFeature &feature)
Retrieves the feature with the specified id into feature.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
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.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
double progress() const
Returns the current progress reported by the feedback object.
Base configuration for geometry checks.
const double tolerance
The tolerance to allow for in geometry checks.
This represents an error reported by a geometry check.
ValueType
Describes the type of an error value.
@ StatusFixed
The error is fixed.
Status status() const
The status of the error.
const QgsVertexId & vidx() const
The id of the affected vertex.
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
QgsGeometryCheckError(const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, QgsVertexId vidx=QgsVertexId(), const QVariant &value=QVariant(), ValueType valueType=ValueOther)
Create a new geometry check error with the parent check and for the layerFeature pair at the errorLoc...
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.
ValueType valueType() const
The type of the value.
QVariant value() const
An additional value for the error.
const QgsGeometryCheck * check() const
The geometry check that created this error.
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.
Base class for geometry checks.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
const QgsGeometryCheckContext * mContext
@ AvailableInValidation
This geometry check should be available in layer validation on the vector layer properties.
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.
Result checkUniqueId(const QgsGeometryCheckerUtils::LayerFeature layerFeature, QMap< QString, QSet< QVariant > > &uniqueIds) const
Checks that there are no duplicated unique IDs.
Result
Result of the geometry checker operation.
@ Canceled
User canceled calculation.
@ Success
Operation completed successfully.
QgsGeometryCheck(const QgsGeometryCheckContext *context, const QVariantMap &configuration)
Create a new geometry check.
const QgsGeometryCheckContext * context() const
Returns the context.
A layer feature combination to uniquely identify and access a feature in a set of layers.
QString layerId() const
The layer id.
QgsFeature feature() const
Returns the feature.
Contains a set of layers and feature ids in those layers to pass to a geometry check.
QgsGeometryMissingVertexCheckError(const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, QgsVertexId vidx=QgsVertexId(), const QVariant &value=QVariant(), ValueType valueType=ValueOther)
Create a new missing vertex check error.
QIcon icon() const override
Returns an icon that should be shown for this kind of error.
void setAffectedAreaBBox(const QgsRectangle &affectedAreaBBox)
Set the bounding box of the affected area.
void setInvolvedFeatures(const QMap< QString, QgsFeatureIds > &involvedFeatures)
The two involved features, that share a common boundary but not all common vertices on this boundary.
QMap< QString, QgsFeatureIds > involvedFeatures() const override
Returns a list of involved features.
QgsRectangle affectedAreaBBox() const override
The bounding box of the affected area of the error.
QgsGeometryCheck::Flags flags() const override
Flags for this geometry check.
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.
QList< Qgis::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
Q_DECL_DEPRECATED QStringList resolutionMethods() const override
Returns a list of descriptions for available resolutions for errors.
QString id() const override
Returns an id for this check.
QgsGeometryCheck::CheckType checkType() const override
Returns the check type.
QgsGeometryCheck::Result collectErrors(const QMap< QString, QgsFeaturePool * > &featurePools, QList< QgsGeometryCheckError * > &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids=LayerFeatureIds()) const override
The main worker method.
ResolutionMethod
The available resolutions for missing vertex check.
@ AddMissingVertex
Add the missing vertex.
QgsGeometryMissingVertexCheck(const QgsGeometryCheckContext *context, const QVariantMap &geometryCheckConfiguration)
Creates a new missing vertex geometry check with context and the provided geometryCheckConfiguration.
static QgsPoint closestVertex(const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
A geometry is the spatial representation of a feature.
double closestSegmentWithContext(const QgsPointXY &point, QgsPointXY &minDistPoint, int &nextVertexIndex, int *leftOrRightOfSegment=nullptr, double epsilon=Qgis::DEFAULT_SEGMENT_EPSILON) const
Searches for the closest segment of geometry to the given point.
QgsVertexIterator vertices() const
Returns a read-only, Java-style iterator for traversal of vertices of all the geometry,...
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool insertVertex(double x, double y, int beforeVertex)
Insert a new vertex before the given vertex index, ring and item (first number is index 0) If the req...
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlag::SkipEmptyInteriorRings)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
Point geometry type, with support for z-dimension and m-values.
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
A rectangle specified with double values.
Represents a vector layer which manages a vector based dataset.
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...
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
#define QgsDebugError(str)
A list of layers and feature ids for each of these layers.
QMap< QString, QgsFeatureIds > toMap() const
Utility class for identifying a unique vertex within a geometry.