28 , mGapThresholdMapUnits( configuration.value( QStringLiteral(
"gapThreshold" ) ).toDouble() )
39 QVector<QgsGeometry> geomList;
46 geomList.append( layerFeature.geometry() );
55 if ( geomList.isEmpty() )
64 std::unique_ptr<QgsAbstractGeometry> unionGeom( geomEngine->combine( geomList, &errMsg ) );
67 messages.append( tr(
"Gap check: %1" ).arg( errMsg ) );
73 std::unique_ptr<QgsAbstractGeometry> envelope( geomEngine->envelope( &errMsg ) );
76 messages.append( tr(
"Gap check: %1" ).arg( errMsg ) );
82 QgsAbstractGeometry *bufEnvelope = geomEngine->buffer( 2, 0, GEOSBUF_CAP_SQUARE, GEOSBUF_JOIN_MITRE, 4. );
83 envelope.reset( bufEnvelope );
87 std::unique_ptr<QgsAbstractGeometry> diffGeom( geomEngine->difference( unionGeom.get(), &errMsg ) );
90 messages.append( tr(
"Gap check: %1" ).arg( errMsg ) );
95 for (
int iPart = 0, nParts = diffGeom->partCount(); iPart < nParts; ++iPart )
100 if ( gapGeom->boundingBox().snappedToGrid( spacing ) == envelope->boundingBox().snappedToGrid( spacing ) )
106 if ( ( mGapThresholdMapUnits > 0 && gapGeom->area() > mGapThresholdMapUnits ) || gapGeom->area() <
mContext->
reducedTolerance )
114 QMap<QString, QgsFeatureIds> neighboringIds;
120 neighboringIds[layerFeature.layer()->id()].insert( layerFeature.feature().id() );
121 gapAreaBBox.
combineExtentWith( layerFeature.geometry().constGet()->boundingBox() );
125 if ( neighboringIds.isEmpty() )
131 double area = gapGeom->area();
138 QMetaEnum metaEnum = QMetaEnum::fromType<QgsGeometryGapCheck::ResolutionMethod>();
139 if ( !metaEnum.isValid() || !metaEnum.valueToKey( method ) )
146 switch ( methodValue )
153 if ( mergeWithNeighbor( featurePools, static_cast<QgsGeometryGapCheckError *>( error ), changes, errMsg ) )
159 error->
setFixFailed( tr(
"Failed to merge with neighbor: %1" ).arg( errMsg ) );
166 bool QgsGeometryGapCheck::mergeWithNeighbor(
const QMap<QString, QgsFeaturePool *> &featurePools,
168 Changes &changes, QString &errMsg )
const 171 QString mergeLayerId;
173 int mergePartIdx = -1;
178 const auto layerIds = err->
neighbors().keys();
180 for (
const QString &layerId : layerIds )
183 std::unique_ptr<QgsAbstractGeometry> errLayerGeom( errGeometry->
clone() );
187 const auto featureIds = err->
neighbors().value( layerId );
192 if ( !featurePool->
getFeature( testId, testFeature ) )
198 for (
int iPart = 0, nParts = testGeom->
partCount(); iPart < nParts; ++iPart )
204 mergeFeature = testFeature;
205 mergePartIdx = iPart;
206 mergeLayerId = layerId;
219 std::unique_ptr<QgsAbstractGeometry> errLayerGeom( errGeometry->
clone() );
240 static QStringList methods = QStringList() << tr(
"Add gap area to neighboring polygon with longest shared edge" ) << tr(
"No action" );
246 return factoryDescription();
256 return factoryFlags();
260 QString QgsGeometryGapCheck::factoryDescription()
265 QString QgsGeometryGapCheck::factoryId()
267 return QStringLiteral(
"QgsGeometryGapCheck" );
270 QgsGeometryCheck::Flags QgsGeometryGapCheck::factoryFlags()
275 QList<QgsWkbTypes::GeometryType> QgsGeometryGapCheck::factoryCompatibleGeometryTypes()
282 return factoryCompatibleGeometryTypes().contains( layer->
geometryType() );
A rectangle specified with double values.
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
bool getFeature(QgsFeatureId id, QgsFeature &feature, QgsFeedback *feedback=nullptr)
Retrieves the feature with the specified id into feature.
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.
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.
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.
Base class for feedback objects to be used for cancelation 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)
QStringList resolutionMethods() const override
Returns a list of descriptions for available resolutions for errors.
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 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, 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.
A feature pool is based on a vector layer and caches features.
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)