QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
31 double layerToMapUnits =
scaleFactor( layerFeature.layer() );
32 for (
int iPart = 0, nParts = geom->
partCount(); iPart < nParts; ++iPart )
36 if ( checkThreshold( layerToMapUnits, part, value ) )
80 else if ( method ==
Delete )
88 if ( mergeWithNeighbor( featurePools, error->
layerId(), feature, vidx.
part, method, mergeAttributeIndices[error->
layerId()], changes, errMsg ) )
94 error->
setFixFailed( tr(
"Failed to merge with neighbor: %1" ).arg( errMsg ) );
103 bool QgsGeometryAreaCheck::checkThreshold(
double layerToMapUnits,
const QgsAbstractGeometry *geom,
double &value )
const
105 value = geom->
area();
106 double threshold = mAreaThreshold / ( layerToMapUnits * layerToMapUnits );
107 return value < threshold;
110 bool QgsGeometryAreaCheck::mergeWithNeighbor(
const QMap<QString, QgsFeaturePool *> &featurePools,
112 int partIdx,
int method,
int mergeAttributeIndex, Changes &changes, QString &errMsg )
const
118 int mergePartIdx = -1;
119 bool matchFound =
false;
128 if ( !featurePool->
getFeature( testId, testFeature ) )
134 for (
int testPartIdx = 0, nTestParts = testGeom->
partCount(); testPartIdx < nTestParts; ++testPartIdx )
136 if ( testId == feature.
id() && testPartIdx == partIdx )
155 val = testGeom->
area();
160 mergeFeature = testFeature;
161 mergePartIdx = testPartIdx;
166 if ( testFeature.
attribute( mergeAttributeIndex ) == feature.
attribute( mergeAttributeIndex ) )
168 mergeFeature = testFeature;
169 mergePartIdx = testPartIdx;
182 if ( !matchFound && maxVal == 0. )
198 if ( mergeFeature.
id() == feature.
id() && mergePartIdx > partIdx )
211 static QStringList methods = QStringList()
212 << tr(
"Merge with neighboring polygon with longest shared edge" )
213 << tr(
"Merge with neighboring polygon with largest area" )
214 << tr(
"Merge with neighboring polygon with identical attribute value, if any, or leave as is" )
215 << tr(
"Delete feature" )
216 << tr(
"No action" );
void setFixFailed(const QString &reason)
Set the error status to failed and specify the reason for failure.
static bool isSingleType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a single type.
void collectErrors(const QMap< QString, QgsFeaturePool * > &featurePools, QList< QgsGeometryCheckError * > &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids=LayerFeatureIds()) const override
The main worker method.
@ ValueArea
The value is an area.
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
void setObsolete()
Set the error status to obsolete.
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.
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.
QMap< QString, QgsFeatureIds > allLayerFeatureIds(const QMap< QString, QgsFeaturePool * > &featurePools) const
Returns all layers and feature ids.
double area() const override SIP_HOLDGIL
Returns the planar, 2-dimensional area of the geometry.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
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.
bool getFeature(QgsFeatureId id, QgsFeature &feature)
Retrieves the feature with the specified id into feature.
QMap< QString, QgsFeatureIds > toMap() const
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
static double sharedEdgeLength(const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol)
void setFixed(int method)
Set the status to fixed and specify the method that has been used to fix the error.
double scaleFactor(const QPointer< QgsVectorLayer > &layer) const
Determines the scale factor of a layer to the map coordinate reference system.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
A layer feature combination to uniquely identify and access a feature in a set of layers.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
const double reducedTolerance
The tolerance to allow for in geometry checks.
A list of layers and feature ids for each of these layers.
const QgsVertexId & vidx() const
The id of the affected vertex.
virtual bool isEmpty() const
Returns true if the geometry is empty.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QSet< QgsFeatureId > QgsFeatureIds
Abstract base class for all geometries.
const QgsGeometryCheckContext * mContext
QgsVectorLayer * layer() const
Gets a pointer to the underlying layer.
bool isValid() const SIP_HOLDGIL
Returns true if the vertex id is valid.
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
A geometry is the spatial representation of a feature.
Contains a set of layers and feature ids in those layers to pass to a geometry check.
Utility class for identifying a unique vertex within a geometry.
static std::unique_ptr< QgsGeometryEngine > createGeomEngine(const QgsAbstractGeometry *geometry, double tolerance)
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_DECL_DEPRECATED QStringList resolutionMethods() const override
Returns a list of descriptions for available resolutions for errors.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QString & layerId() const
The id of the layer on which this error has been detected.
void deleteFeatureGeometryPart(const QMap< QString, QgsFeaturePool * > &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, Changes &changes) const
Deletes a part of a feature geometry.
This represents an error reported by a geometry check.
QgsFeatureIds getIntersects(const QgsRectangle &rect) const
Gets all feature ids in the bounding box rect.
A feature pool is based on a vector layer and caches features.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
@ MergeIdenticalAttribute