QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
26 , mOverlapThresholdMapUnits( configurationValue<double>( QStringLiteral(
"maxOverlapArea" ) ) )
36 QList<QString> layerIds = featureIds.keys();
43 layerIds.removeOne( layerFeatureA.layer()->id() );
48 geomEngineA->prepareGeometry();
49 if ( !geomEngineA->isValid() )
51 messages.append( tr(
"Overlap check failed for (%1): the geometry is invalid" ).arg( layerFeatureA.id() ) );
62 if ( layerFeatureA.layerId() == layerFeatureB.layerId() && layerFeatureB.feature().id() >= layerFeatureA.feature().id() )
68 const QgsGeometry geometryB = layerFeatureB.geometry();
70 if ( geomEngineA->overlaps( geomB, &errMsg ) )
72 std::unique_ptr<QgsAbstractGeometry> interGeom( geomEngineA->intersection( geomB ) );
73 if ( interGeom && !interGeom->isEmpty() )
76 for (
int iPart = 0, nParts = interGeom->partCount(); iPart < nParts; ++iPart )
79 double area = interPart->
area();
86 else if ( !errMsg.isEmpty() )
88 messages.append( tr(
"Overlap check between features %1 and %2 %3" ).arg( layerFeatureA.id(), layerFeatureB.id(), errMsg ) );
116 geomEngineA->prepareGeometry();
119 if ( !geomEngineA->overlaps( geometryB.
constGet() ) )
124 std::unique_ptr< QgsAbstractGeometry > interGeom( geomEngineA->intersection( geometryB.
constGet(), &errMsg ) );
127 error->
setFixFailed( tr(
"Failed to compute intersection between overlapping features: %1" ).arg( errMsg ) );
133 for (
int iPart = 0, nParts = interGeom->partCount(); iPart < nParts; ++iPart )
143 if ( !interPart || interPart->
isEmpty() )
156 std::unique_ptr< QgsAbstractGeometry > diff1( geomEngineA->difference( interPart, &errMsg ) );
157 if ( !diff1 || diff1->isEmpty() )
166 geomEngineB->prepareGeometry();
167 std::unique_ptr< QgsAbstractGeometry > diff2( geomEngineB->difference( interPart, &errMsg ) );
168 if ( !diff2 || diff2->isEmpty() )
178 if ( !diff1 || !diff2 || shared1 == 0. || shared2 == 0. )
180 error->
setFixFailed( tr(
"Could not find shared edges between intersection and overlapping features" ) );
184 if ( shared1 < shared2 )
214 static QStringList methods = QStringList()
215 << tr(
"Remove overlapping area from neighboring polygon with shortest shared edge" )
216 << tr(
"No action" );
222 return factoryDescription();
232 return factoryFlags();
236 QString QgsGeometryOverlapCheck::factoryDescription()
238 return tr(
"Overlap" );
246 QString QgsGeometryOverlapCheck::factoryId()
248 return QStringLiteral(
"QgsGeometryOverlapCheck" );
251 QgsGeometryCheck::Flags QgsGeometryOverlapCheck::factoryFlags()
256 QList<QgsWkbTypes::GeometryType> QgsGeometryOverlapCheck::factoryCompatibleGeometryTypes()
263 return factoryCompatibleGeometryTypes().contains( layer->geometryType() );
269 , mOverlappedFeature(
OverlappedFeature( overlappedFeature.layer(), overlappedFeature.feature().id() ) )
297 if ( changes.value( mOverlappedFeature.
layerId() ).keys().contains( mOverlappedFeature.
featureId() ) )
306 return QCoreApplication::translate(
"QgsGeometryTypeCheckError",
"Overlap with %1 at feature %2" ).arg( mOverlappedFeature.
layerName(), QString::number( mOverlappedFeature.
featureId() ) );
311 QMap<QString, QgsFeatureIds> features;
313 features[mOverlappedFeature.
layerId()].insert( mOverlappedFeature.
featureId() );
QVariant value() const
An additional value for the error.
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.
Descripts a change to fix a geometry.
@ Subtract
Subtract the overlap region from the polygon.
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
@ ChangeFeature
This change happens on feature level.
@ StatusFixed
The error is fixed.
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 setObsolete()
Set the error status to obsolete.
bool handleChanges(const QgsGeometryCheck::Changes &changes) override
Apply a list of changes.
QgsGeometryOverlapCheck(const QgsGeometryCheckContext *context, const QVariantMap &configuration)
Checks for overlapping polygons.
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
QMap< QString, QgsFeatureIds > allLayerFeatureIds(const QMap< QString, QgsFeaturePool * > &featurePools) const
Returns all layers and feature ids.
QgsGeometry geometry() const
Returns the geometry of this feature.
QString layerName() const
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
@ LayerCheck
The check controls a whole layer (topology checks)
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 QgsGeometryCheckContext * context() const
Returns the context.
@ ChangeChanged
Something has been updated.
bool getFeature(QgsFeatureId id, QgsFeature &feature)
Retrieves the feature with the specified id into feature.
@ NoChange
Do not change anything.
QgsGeometryOverlapCheckError(const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsGeometry &geometry, const QgsPointXY &errorLocation, const QVariant &value, const QgsGeometryCheckerUtils::LayerFeature &overlappedFeature)
Creates a new overlap check error for check and the layerFeature combination.
QMap< QString, QgsFeatureIds > toMap() const
Q_DECL_DEPRECATED QStringList resolutionMethods() const override
Returns a list of descriptions for available resolutions for errors.
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
QgsGeometryCheck::Flags flags() const override
Flags for this geometry check.
QString description() const override
The error description.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
static double sharedEdgeLength(const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol)
virtual void updateFeature(QgsFeature &feature)=0
Updates a feature in this pool.
void setFixed(int method)
Set the status to fixed and specify the method that has been used to fix the error.
virtual bool handleChanges(const QgsGeometryCheck::Changes &changes)
Apply a list of changes.
const QgsPointXY & location() const
The location of the error in map units.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
QString description() const override
Returns a human readable description for this check.
const QgsCoordinateReferenceSystem mapCrs
The coordinate system in which calculations should be done.
Status status() const
The status of the error.
QMap< QString, QgsFeatureIds > involvedFeatures() const override
Returns a list of involved features.
const double reducedTolerance
The tolerance to allow for in geometry checks.
A list of layers and feature ids for each of these layers.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
virtual bool isEmpty() const
Returns true if the geometry is empty.
QgsCoordinateReferenceSystem crs() const
The coordinate reference system of this layer.
Abstract base class for all geometries.
const QgsGeometryCheckContext * mContext
QgsFeatureId featureId() const
@ AvailableInValidation
This geometry check should be available in layer validation on the vector layer peroperties.
bool isCanceled() const
Tells whether the operation has been canceled already.
QString id() const override
Returns an id for this check.
static void filter1DTypes(QgsAbstractGeometry *geom)
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
CheckType
The type of a check.
Utility class for identifying a unique vertex within a geometry.
const double tolerance
The tolerance to allow for in geometry checks.
bool closeMatch(QgsGeometryCheckError *other) const override
Check if this error is almost equal to other.
const QgsGeometryCheck * mCheck
static std::unique_ptr< QgsGeometryEngine > createGeomEngine(const QgsAbstractGeometry *geometry, double tolerance)
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
const QString & layerId() const
The id of the layer on which this error has been detected.
const QgsCoordinateTransformContext transformContext
The coordinate transform context with which transformations will be done.
const OverlappedFeature & overlappedFeature() const
Returns the overlapped feature.
static bool pointsFuzzyEqual(const QgsPointXY &p1, const QgsPointXY &p2, double tol)
Determine whether two points are equal up to the specified tolerance.
bool isEqual(QgsGeometryCheckError *other) const override
Check if this error is equal to other.