29 , mGapThresholdMapUnits( configuration.value( QStringLiteral(
"gapThreshold" ) ).toDouble() )
40 QVector<QgsGeometry> geomList;
47 geomList.append( layerFeature.geometry() );
56 if ( geomList.isEmpty() )
62 geomEngine->prepareGeometry();
66 std::unique_ptr<QgsAbstractGeometry> unionGeom( geomEngine->combine( geomList, &errMsg ) );
69 messages.append( tr(
"Gap check: %1" ).arg( errMsg ) );
75 geomEngine->prepareGeometry();
76 std::unique_ptr<QgsAbstractGeometry> envelope( geomEngine->envelope( &errMsg ) );
79 messages.append( tr(
"Gap check: %1" ).arg( errMsg ) );
85 geomEngine->prepareGeometry();
86 QgsAbstractGeometry *bufEnvelope = geomEngine->buffer( 2, 0, GEOSBUF_CAP_SQUARE, GEOSBUF_JOIN_MITRE, 4. );
87 envelope.reset( bufEnvelope );
91 geomEngine->prepareGeometry();
92 std::unique_ptr<QgsAbstractGeometry> diffGeom( geomEngine->difference( unionGeom.get(), &errMsg ) );
95 messages.append( tr(
"Gap check: %1" ).arg( errMsg ) );
100 for (
int iPart = 0, nParts = diffGeom->partCount(); iPart < nParts; ++iPart )
105 if ( gapGeom->boundingBox().snappedToGrid( spacing ) == envelope->boundingBox().snappedToGrid( spacing ) )
111 if ( ( mGapThresholdMapUnits > 0 && gapGeom->area() > mGapThresholdMapUnits ) || gapGeom->area() <
mContext->
reducedTolerance )
119 QMap<QString, QgsFeatureIds> neighboringIds;
126 neighboringIds[layerFeature.layer()->id()].insert( layerFeature.feature().id() );
131 if ( neighboringIds.isEmpty() )
137 double area = gapGeom->area();
144 QMetaEnum metaEnum = QMetaEnum::fromType<QgsGeometryGapCheck::ResolutionMethod>();
145 if ( !metaEnum.isValid() || !metaEnum.valueToKey( method ) )
152 switch ( methodValue )
159 if ( mergeWithNeighbor( featurePools, static_cast<QgsGeometryGapCheckError *>( error ), changes, errMsg ) )
165 error->
setFixFailed( tr(
"Failed to merge with neighbor: %1" ).arg( errMsg ) );
172 bool QgsGeometryGapCheck::mergeWithNeighbor(
const QMap<QString, QgsFeaturePool *> &featurePools,
174 Changes &changes, QString &errMsg )
const 177 QString mergeLayerId;
179 int mergePartIdx = -1;
184 const auto layerIds = err->
neighbors().keys();
186 for (
const QString &layerId : layerIds )
189 std::unique_ptr<QgsAbstractGeometry> errLayerGeom( errGeometry->
clone() );
193 const auto featureIds = err->
neighbors().value( layerId );
198 if ( !featurePool->
getFeature( testId, testFeature ) )
204 for (
int iPart = 0, nParts = testGeom->
partCount(); iPart < nParts; ++iPart )
210 mergeFeature = testFeature;
211 mergePartIdx = iPart;
212 mergeLayerId = layerId;
225 std::unique_ptr<QgsAbstractGeometry> errLayerGeom( errGeometry->
clone() );
246 static QStringList methods = QStringList() << tr(
"Add gap area to neighboring polygon with longest shared edge" ) << tr(
"No action" );
252 return factoryDescription();
262 return factoryFlags();
266 QString QgsGeometryGapCheck::factoryDescription()
271 QString QgsGeometryGapCheck::factoryId()
273 return QStringLiteral(
"QgsGeometryGapCheck" );
276 QgsGeometryCheck::Flags QgsGeometryGapCheck::factoryFlags()
281 QList<QgsWkbTypes::GeometryType> QgsGeometryGapCheck::factoryCompatibleGeometryTypes()
288 return factoryCompatibleGeometryTypes().contains( layer->
geometryType() );
306 return err && err->
layerId() == layerId() && err->
neighbors() == neighbors();
314 mNeighbors = err->mNeighbors;
315 mGapAreaBBox = err->mGapAreaBBox;
A rectangle specified with double values.
static bool pointsFuzzyEqual(const QgsPointXY &p1, const QgsPointXY &p2, double tol)
Determine whether two points are equal up to the specified tolerance.
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
virtual void update(const QgsGeometryCheckError *other)
Update this error with the information from other.
bool closeMatch(QgsGeometryCheckError *other) const override
Check if this error is almost equal to other.
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
double progress() const
Returns the current progress reported by the feedback object.
const QgsCoordinateReferenceSystem mapCrs
The coordinate system in which calculations should be done.
QString description() const override
Returns a human readable description for this check.
const QgsPointXY & location() const
The location of the error in map units.
void setProgress(double progress)
Sets the current progress for the feedback object.
QMap< QString, QgsFeatureIds > toMap() const
Contains a set of layers and feature ids in those layers to pass to a geometry check.
CheckType
The type of a check.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
A geometry is the spatial representation of a feature.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
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.
void setFixFailed(const QString &reason)
Set the error status to failed and specify the reason for failure.
QIcon icon() const override
Returns an icon that should be shown for this kind of error.
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Base configuration for geometry checks.
An error produced by a QgsGeometryGapCheck.
static double sharedEdgeLength(const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol)
void update(const QgsGeometryCheckError *other) override
Update this error with the information from other.
QStringList resolutionMethods() const override
Returns a list of descriptions for available resolutions for errors.
bool getFeature(QgsFeatureId id, QgsFeature &feature)
Retrieves the feature with the specified id into feature.
bool isEqual(QgsGeometryCheckError *other) const override
Check if this error is equal to other.
A layer feature combination to uniquely identify and access a feature in a set of layers...
This class implements a geometry check.
QgsGeometryCheck::Flags flags() const override
Flags for this geometry check.
Abstract base class for all geometries.
QMap< QString, QgsFeatureIds > allLayerFeatureIds(const QMap< QString, QgsFeaturePool *> &featurePools) const
Returns all layers and feature ids.
const QString & layerId() const
The id of the layer on which this error has been detected.
const double tolerance
The tolerance to allow for in geometry checks.
ResolutionMethod
Resolution methods for geometry gap checks.
const QgsGeometryCheckContext * mContext
const double reducedTolerance
The tolerance to allow for in geometry checks.
A list of layers and feature ids for each of these layers.
const QMap< QString, QgsFeatureIds > & neighbors() const
A map of layers and feature ids of the neighbors of the gap.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsGeometry geometry() const
The geometry of the error in map units.
static bool isSingleType(Type type)
Returns true if the WKB type is a single type.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
QgsGeometryGapCheck(const QgsGeometryCheckContext *context, const QVariantMap &configuration)
The configuration accepts a "gapThreshold" key which specifies the maximum gap size in squared map un...
QMap< QString, QgsFeatureIds > involvedFeatures() const override
Returns a list of involved features.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
bool isCanceled() const
Tells whether the operation has been canceled already.
void fixError(const QMap< QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap< QString, int > &mergeAttributeIndices, Changes &changes) const override
Fix the error error with the specified method.
bool handleChanges(const QgsGeometryCheck::Changes &) override
Apply a list of changes.
A feature pool is based on a vector layer and caches features.
QgsRectangle affectedAreaBBox() const override
The bounding box of the affected area of the error.
void setFixed(int method)
Set the status to fixed and specify the method that has been used to fix the error.
void collectErrors(const QMap< QString, QgsFeaturePool *> &featurePools, QList< QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids=LayerFeatureIds()) const override
The main worker method.
const QgsCoordinateTransformContext transformContext
The coordinate transform context with which transformations will be done.
QgsCoordinateReferenceSystem crs() const
The coordinate reference system of this layer.
const QgsGeometryCheckContext * context() const
Returns the context.
This represents an error reported by a geometry check.
static std::unique_ptr< QgsGeometryEngine > createGeomEngine(const QgsAbstractGeometry *geometry, double tolerance)
Represents a vector layer which manages a vector based data sets.
QString id() const override
Returns an id for this check.
Merge the gap with the polygon with the longest shared edge.
This geometry check should be available in layer validation on the vector layer peroperties.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
The check controls a whole layer (topology checks)