QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsgeometrygapcheck.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometrygapcheck.h
3  ---------------------
4  begin : September 2015
5  copyright : (C) 2014 by Sandro Mani / Sourcepole AG
6  email : smani at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #define SIP_NO_FILE
17 
18 #ifndef QGS_GEOMETRY_GAP_CHECK_H
19 #define QGS_GEOMETRY_GAP_CHECK_H
20 
21 #include "qgsgeometrycheck.h"
22 #include "qgsgeometrycheckerror.h"
23 #include "qgsfeatureid.h"
24 
31 class ANALYSIS_EXPORT QgsGeometryGapCheckError : public QgsGeometryCheckError
32 {
33  public:
34 
42  const QString &layerId,
43  const QgsGeometry &geometry,
44  const QMap<QString, QgsFeatureIds> &neighbors,
45  double area,
46  const QgsRectangle &gapAreaBBox,
47  const QgsRectangle &contextArea )
48  : QgsGeometryCheckError( check, layerId, FID_NULL, geometry, geometry.constGet()->centroid(), QgsVertexId(), area, ValueArea )
49  , mNeighbors( neighbors )
50  , mGapAreaBBox( gapAreaBBox )
51  , mContextBoundingBox( contextArea )
52  {
53  }
54 
55  QgsRectangle contextBoundingBox() const override;
56 
60  const QMap<QString, QgsFeatureIds> &neighbors() const { return mNeighbors; }
61 
62  bool isEqual( QgsGeometryCheckError *other ) const override;
63 
64  bool closeMatch( QgsGeometryCheckError *other ) const override;
65 
66  void update( const QgsGeometryCheckError *other ) override;
67 
68  bool handleChanges( const QgsGeometryCheck::Changes & /*changes*/ ) override;
69 
70  QgsRectangle affectedAreaBBox() const override;
71 
72  QMap<QString, QgsFeatureIds > involvedFeatures() const override;
73 
74  QIcon icon() const override;
75 
76  private:
77  QMap<QString, QgsFeatureIds> mNeighbors;
78  QgsRectangle mGapAreaBBox;
79  QgsRectangle mContextBoundingBox;
80 };
81 
82 
89 class ANALYSIS_EXPORT QgsGeometryGapCheck : public QgsGeometryCheck
90 {
91  Q_GADGET
92  Q_DECLARE_TR_FUNCTIONS( QgsGeometryGapCheck )
93 
94  public:
97  {
103  };
104  Q_ENUM( ResolutionMethod )
105 
106 
112  explicit QgsGeometryGapCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
113 
114  void prepare( const QgsGeometryCheckContext *context, const QVariantMap &configuration ) override;
115 
116  QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return factoryCompatibleGeometryTypes(); }
117  void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
118  void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
119  Q_DECL_DEPRECATED QStringList resolutionMethods() const override;
120 
121  QList<QgsGeometryCheckResolutionMethod> availableResolutionMethods() const override;
122 
123  QString description() const override;
124  QString id() const override;
125  QgsGeometryCheck::Flags flags() const override;
126  QgsGeometryCheck::CheckType checkType() const override { return factoryCheckType(); }
127 
129  static QString factoryDescription() SIP_SKIP;
130  static QString factoryId() SIP_SKIP;
131  static QgsGeometryCheck::Flags factoryFlags() SIP_SKIP;
132  static QList<QgsWkbTypes::GeometryType> factoryCompatibleGeometryTypes() SIP_SKIP;
133  static bool factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP;
134  static QgsGeometryCheck::CheckType factoryCheckType() SIP_SKIP;
136 
137  private:
138  enum Condition
139  {
140  LongestSharedEdge,
141  LargestArea
142  };
143 
144  bool mergeWithNeighbor( const QMap<QString, QgsFeaturePool *> &featurePools,
145  QgsGeometryGapCheckError *err, Changes &changes, QString &errMsg, Condition condition ) const;
146 
147  const double mGapThresholdMapUnits;
148  QgsWeakMapLayerPointer mAllowedGapsLayer;
149  std::unique_ptr<QgsVectorLayerFeatureSource> mAllowedGapsSource;
150  double mAllowedGapsBuffer = 0;
151 
152 };
153 
154 #endif // QGS_GEOMETRY_GAP_CHECK_H
QgsGeometryCheck::prepare
virtual void prepare(const QgsGeometryCheckContext *context, const QVariantMap &configuration)
Will be run in the main thread before collectErrors is called (which may be run from a background thr...
Definition: qgsgeometrycheck.cpp:34
QgsGeometryCheckError::contextBoundingBox
virtual QgsRectangle contextBoundingBox() const
The context of the error.
Definition: qgsgeometrycheckerror.cpp:88
QgsGeometryCheckError::closeMatch
virtual bool closeMatch(QgsGeometryCheckError *) const
Check if this error is almost equal to other.
Definition: qgsgeometrycheckerror.cpp:123
QgsGeometryGapCheckError::neighbors
const QMap< QString, QgsFeatureIds > & neighbors() const
A map of layers and feature ids of the neighbors of the gap.
Definition: qgsgeometrygapcheck.h:60
QgsGeometryGapCheck::AddToAllowedGaps
@ AddToAllowedGaps
Add gap geometry to allowed gaps layer.
Definition: qgsgeometrygapcheck.h:100
QgsGeometryGapCheck::compatibleGeometryTypes
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
Definition: qgsgeometrygapcheck.h:116
QgsMeshUtils::centroid
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
Definition: qgstriangularmesh.cpp:955
QgsGeometryCheck::Changes
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
Definition: qgsgeometrycheck.h:220
QgsGeometryCheck::description
virtual QString description() const =0
Returns a human readable description for this check.
FID_NULL
#define FID_NULL
Definition: qgsfeatureid.h:29
qgsfeatureid.h
QgsGeometryCheck::resolutionMethods
virtual Q_DECL_DEPRECATED QStringList resolutionMethods() const
Returns a list of descriptions for available resolutions for errors.
Definition: qgsgeometrycheck.cpp:77
qgsgeometrycheckerror.h
QgsGeometryCheck::collectErrors
virtual void collectErrors(const QMap< QString, QgsFeaturePool * > &featurePools, QList< QgsGeometryCheckError * > &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids=QgsGeometryCheck::LayerFeatureIds()) const =0
The main worker method.
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsGeometryGapCheck::CreateNewFeature
@ CreateNewFeature
Create a new feature with the gap geometry.
Definition: qgsgeometrygapcheck.h:101
QgsGeometryGapCheckError::QgsGeometryGapCheckError
QgsGeometryGapCheckError(const QgsGeometryCheck *check, const QString &layerId, const QgsGeometry &geometry, const QMap< QString, QgsFeatureIds > &neighbors, double area, const QgsRectangle &gapAreaBBox, const QgsRectangle &contextArea)
Create a new gap check error produced by check on the layer layerId.
Definition: qgsgeometrygapcheck.h:41
QgsGeometryCheck
This class implements a geometry check.
Definition: qgsgeometrycheck.h:91
QgsGeometryCheck::flags
virtual QgsGeometryCheck::Flags flags() const
Flags for this geometry check.
Definition: qgsgeometrycheck.cpp:45
QgsGeometryCheck::fixError
virtual void fixError(const QMap< QString, QgsFeaturePool * > &featurePools, QgsGeometryCheckError *error, int method, const QMap< QString, int > &mergeAttributeIndices, Changes &changes) const
Fixes the error error with the specified method.
Definition: qgsgeometrycheck.cpp:50
QgsGeometryCheck::id
virtual QString id() const =0
Returns an id for this check.
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsGeometryGapCheck::NoChange
@ NoChange
Do not handle the error.
Definition: qgsgeometrygapcheck.h:99
qgsgeometrycheck.h
QgsGeometryCheckError::affectedAreaBBox
virtual QgsRectangle affectedAreaBBox() const
The bounding box of the affected area of the error.
Definition: qgsgeometrycheckerror.cpp:93
QgsGeometryCheckError::handleChanges
virtual bool handleChanges(const QgsGeometryCheck::Changes &changes)
Apply a list of changes.
Definition: qgsgeometrycheckerror.cpp:128
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsGeometryCheck::availableResolutionMethods
virtual QList< QgsGeometryCheckResolutionMethod > availableResolutionMethods() const
Returns a list of available resolution methods.
Definition: qgsgeometrycheck.cpp:59
QgsGeometryGapCheckError
An error produced by a QgsGeometryGapCheck.
Definition: qgsgeometrygapcheck.h:31
QgsGeometryGapCheck::MergeLongestEdge
@ MergeLongestEdge
Merge the gap with the polygon with the longest shared edge.
Definition: qgsgeometrygapcheck.h:98
QgsGeometryCheckContext
Base configuration for geometry checks.
Definition: qgsgeometrycheckcontext.h:31
QgsWeakMapLayerPointer
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:2146
QgsGeometryCheckError::isEqual
virtual bool isEqual(QgsGeometryCheckError *other) const
Check if this error is equal to other.
Definition: qgsgeometrycheckerror.cpp:115
QgsGeometryGapCheck::MergeLargestArea
@ MergeLargestArea
Merge with neighbouring polygon with largest area.
Definition: qgsgeometrygapcheck.h:102
QgsGeometryGapCheck::checkType
QgsGeometryCheck::CheckType checkType() const override
Returns the check type.
Definition: qgsgeometrygapcheck.h:126
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsGeometryCheck::CheckType
CheckType
The type of a check.
Definition: qgsgeometrycheck.h:154
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsvertexid.h:30
QgsGeometryCheckError::update
virtual void update(const QgsGeometryCheckError *other)
Update this error with the information from other.
Definition: qgsgeometrycheckerror.cpp:207
QgsGeometryGapCheck
Checks for gaps between neighbouring polygons.
Definition: qgsgeometrygapcheck.h:89
QgsWkbTypes
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:41
QgsGeometryGapCheck::ResolutionMethod
ResolutionMethod
Resolution methods for geometry gap checks.
Definition: qgsgeometrygapcheck.h:96
QgsGeometryCheckError
This represents an error reported by a geometry check.
Definition: qgsgeometrycheckerror.h:35
QgsGeometryCheckError::icon
virtual QIcon icon() const
Returns an icon that should be shown for this kind of error.
Definition: qgsgeometrycheckerror.cpp:199
QgsGeometryCheckError::involvedFeatures
virtual QMap< QString, QgsFeatureIds > involvedFeatures() const
Returns a list of involved features.
Definition: qgsgeometrycheckerror.cpp:194