QGIS API Documentation  3.6.0-Noosa (5873452)
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  : QgsGeometryCheckError( check, layerId, FID_NULL, geometry, geometry.constGet()->centroid(), QgsVertexId(), area, ValueArea )
48  , mNeighbors( neighbors )
49  , mGapAreaBBox( gapAreaBBox )
50  {
51  }
52 
56  const QMap<QString, QgsFeatureIds> &neighbors() const { return mNeighbors; }
57 
58  bool isEqual( QgsGeometryCheckError *other ) const override
59  {
60  QgsGeometryGapCheckError *err = dynamic_cast<QgsGeometryGapCheckError *>( other );
61  return err && QgsGeometryCheckerUtils::pointsFuzzyEqual( err->location(), location(), mCheck->context()->reducedTolerance ) && err->neighbors() == neighbors();
62  }
63 
64  bool closeMatch( QgsGeometryCheckError *other ) const override
65  {
66  QgsGeometryGapCheckError *err = dynamic_cast<QgsGeometryGapCheckError *>( other );
67  return err && err->layerId() == layerId() && err->neighbors() == neighbors();
68  }
69 
70  void update( const QgsGeometryCheckError *other ) override
71  {
73  // Static cast since this should only get called if isEqual == true
74  const QgsGeometryGapCheckError *err = static_cast<const QgsGeometryGapCheckError *>( other );
75  mNeighbors = err->mNeighbors;
76  mGapAreaBBox = err->mGapAreaBBox;
77  }
78 
79  bool handleChanges( const QgsGeometryCheck::Changes & /*changes*/ ) override
80  {
81  return true;
82  }
83 
84  QgsRectangle affectedAreaBBox() const override
85  {
86  return mGapAreaBBox;
87  }
88 
89  private:
90  QMap<QString, QgsFeatureIds> mNeighbors;
91  QgsRectangle mGapAreaBBox;
92 };
93 
94 
101 class ANALYSIS_EXPORT QgsGeometryGapCheck : public QgsGeometryCheck
102 {
103  Q_GADGET
104  public:
107  {
109  NoChange
110  };
111  Q_ENUM( ResolutionMethod )
112 
113 
119  explicit QgsGeometryGapCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
120 
121  QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return factoryCompatibleGeometryTypes(); }
122  void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
123  void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
124  QStringList resolutionMethods() const override;
125 
126  QString description() const override;
127  QString id() const override;
128  QgsGeometryCheck::Flags flags() const override;
129  QgsGeometryCheck::CheckType checkType() const override { return factoryCheckType(); }
130 
132  static QString factoryDescription() SIP_SKIP;
133  static QString factoryId() SIP_SKIP;
134  static QgsGeometryCheck::Flags factoryFlags() SIP_SKIP;
135  static QList<QgsWkbTypes::GeometryType> factoryCompatibleGeometryTypes() SIP_SKIP;
136  static bool factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP;
137  static QgsGeometryCheck::CheckType factoryCheckType() SIP_SKIP;
139 
140  private:
141  bool mergeWithNeighbor( const QMap<QString, QgsFeaturePool *> &featurePools,
142  QgsGeometryGapCheckError *err, Changes &changes, QString &errMsg ) const;
143 
144  const double mGapThresholdMapUnits;
145 };
146 
147 #endif // QGS_GEOMETRY_GAP_CHECK_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
static bool pointsFuzzyEqual(const QgsPointXY &p1, const QgsPointXY &p2, double tol)
Determine whether two points are equal up to the specified tolerance.
QgsGeometryGapCheckError(const QgsGeometryCheck *check, const QString &layerId, const QgsGeometry &geometry, const QMap< QString, QgsFeatureIds > &neighbors, double area, const QgsRectangle &gapAreaBBox)
Create a new gap check error produced by check on the layer layerId.
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.
Checks for gaps between neighbouring polygons.
#define FID_NULL
Definition: qgsfeatureid.h:26
const QgsPointXY & location() const
The location of the error in map units.
CheckType
The type of a check.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
Base configuration for geometry checks.
An error produced by a QgsGeometryGapCheck.
void update(const QgsGeometryCheckError *other) override
Update this error with the information from other.
Utility class for identifying a unique vertex within a geometry.
#define SIP_SKIP
Definition: qgis_sip.h:119
virtual QString id() const =0
Returns an id for this check.
This class implements a geometry check.
const QString & layerId() const
The id of the layer on which this error has been detected.
ResolutionMethod
Resolution methods for geometry gap checks.
QgsGeometryCheck::CheckType checkType() const override
Returns the check type.
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.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
bool handleChanges(const QgsGeometryCheck::Changes &) override
Apply a list of changes.
virtual QString description() const =0
Returns a human readable description for this check.
virtual void fixError(const QMap< QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap< QString, int > &mergeAttributeIndices, Changes &changes) const
Fix the error error with the specified method.
QgsRectangle affectedAreaBBox() const override
The bounding box of the affected area of the error.
bool isEqual(QgsGeometryCheckError *other) const override
Check if this error is equal to other.
virtual QStringList resolutionMethods() const =0
Returns a list of descriptions for available resolutions for errors.
virtual QgsGeometryCheck::Flags flags() const
Flags for this geometry check.
This represents an error reported by a geometry check.
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.
Represents a vector layer which manages a vector based data sets.
Merge the gap with the polygon with the longest shared edge.