QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsgeometrycheck.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometrycheck.h
3  ---------------------
4  begin : September 2014
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 #ifndef QGS_GEOMETRY_CHECK_H
17 #define QGS_GEOMETRY_CHECK_H
18 
19 #include <QApplication>
20 #include <limits>
21 #include <QStringList>
22 #include <QPointer>
23 
24 #include "qgis_analysis.h"
25 #include "qgsfeature.h"
26 #include "qgsvectorlayer.h"
27 #include "qgsgeometry.h"
30 #include "qgssettings.h"
31 
33 class QgsFeaturePool;
34 
91 class ANALYSIS_EXPORT QgsGeometryCheck
92 {
93  Q_GADGET
94 
95  public:
96 
104  struct ANALYSIS_EXPORT LayerFeatureIds
105  {
106  LayerFeatureIds() = default;
107  LayerFeatureIds( const QMap<QString, QgsFeatureIds> &idsIn ) SIP_SKIP;
108 
109  QMap<QString, QgsFeatureIds> ids SIP_SKIP;
110 
111 #ifndef SIP_RUN
112  QMap<QString, QgsFeatureIds> toMap() const
113  {
114  return ids;
115  }
116 
117  bool isEmpty() const
118  {
119  return ids.isEmpty();
120  }
121 #endif
122  };
123 
130  {
134  ChangeNode
135  };
136 
143  {
146  ChangeChanged
147  };
148 
155  {
158  LayerCheck
159  };
160 
164  enum Flag
165  {
166  AvailableInValidation = 1 << 1
167  };
168  Q_DECLARE_FLAGS( Flags, Flag )
169  Q_FLAG( Flags )
170 
171 
176  struct Change
177  {
178  Change() = default;
179 
184  : what( _what )
185  , type( _type )
186  , vidx( _vidx )
187  {}
188 
193 
198 
204  {
205  return what == other.what && type == other.type && vidx == other.vidx;
206  }
207  };
208 
213  typedef QMap<QString, QMap<QgsFeatureId, QList<QgsGeometryCheck::Change> > > Changes;
214 
218  QgsGeometryCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
219  virtual ~QgsGeometryCheck() = default;
220 
226  virtual void prepare( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
227 
228 #ifndef SIP_RUN
229 
234  template <class T>
235  T configurationValue( const QString &name, const QVariant &defaultValue = QVariant() )
236  {
237  return mConfiguration.value( name, QgsSettings().value( "/geometry_checker/" + id() + "/" + name, defaultValue ) ).value<T>();
238  }
239 #endif
240 
247  virtual bool isCompatible( QgsVectorLayer *layer ) const;
248 
254  virtual QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const = 0;
255 
259  virtual QgsGeometryCheck::Flags flags() const;
260 
269  virtual void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors SIP_INOUT, QStringList &messages SIP_INOUT, QgsFeedback *feedback, const LayerFeatureIds &ids = QgsGeometryCheck::LayerFeatureIds() ) const = 0;
270 
278  virtual void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes SIP_INOUT ) const SIP_SKIP;
279 
285  virtual QList<QgsGeometryCheckResolutionMethod> availableResolutionMethods() const;
286 
294  Q_DECL_DEPRECATED virtual QStringList resolutionMethods() const SIP_DEPRECATED;
295 
301  virtual QString description() const = 0;
302 
308  virtual QString id() const = 0;
309 
315  virtual CheckType checkType() const = 0;
316 
322  const QgsGeometryCheckContext *context() const { return mContext; }
323 
324  protected:
325 
332  QMap<QString, QgsFeatureIds> allLayerFeatureIds( const QMap<QString, QgsFeaturePool *> &featurePools ) const SIP_SKIP;
333 
340  void replaceFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, QgsAbstractGeometry *newPartGeom, Changes &changes ) const SIP_SKIP;
341 
348  void deleteFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, Changes &changes ) const SIP_SKIP;
349 
356  void deleteFeatureGeometryRing( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, int ringIdx, Changes &changes ) const SIP_SKIP;
357 
359  QVariantMap mConfiguration;
360 
367  double scaleFactor( const QPointer<QgsVectorLayer> &layer ) const SIP_SKIP;
368 };
369 
370 #endif // QGS_GEOMETRY_CHECK_H
QgsGeometryCheck::Change
Descripts a change to fix a geometry.
Definition: qgsgeometrycheck.h:177
QgsGeometryCheck::compatibleGeometryTypes
virtual QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const =0
A list of geometry types for which this check can be performed.
QgsGeometryCheck::ChangeType
ChangeType
Description of the type of a change.
Definition: qgsgeometrycheck.h:143
QgsGeometryCheck::Flag
Flag
Flags for geometry checks.
Definition: qgsgeometrycheck.h:165
QgsGeometryCheck::ChangeAdded
@ ChangeAdded
Something has been added.
Definition: qgsgeometrycheck.h:144
QgsGeometryCheck::ChangeFeature
@ ChangeFeature
This change happens on feature level.
Definition: qgsgeometrycheck.h:131
QgsGeometryCheck::Change::Change
Change(QgsGeometryCheck::ChangeWhat _what, QgsGeometryCheck::ChangeType _type, QgsVertexId _vidx=QgsVertexId())
Create a new Change.
Definition: qgsgeometrycheck.h:183
QgsGeometryCheck::Change::what
QgsGeometryCheck::ChangeWhat what
What level this change affects.
Definition: qgsgeometrycheck.h:192
QgsGeometryCheck::Changes
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
Definition: qgsgeometrycheck.h:213
QgsGeometryCheck::LayerFeatureIds::isEmpty
bool isEmpty() const
Definition: qgsgeometrycheck.h:117
qgsfeature.h
QgsGeometryCheck::FeatureNodeCheck
@ FeatureNodeCheck
The check controls individual nodes.
Definition: qgsgeometrycheck.h:156
QgsGeometryCheck::mConfiguration
QVariantMap mConfiguration
Definition: qgsgeometrycheck.h:359
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
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.
QgsGeometryCheck::LayerFeatureIds::toMap
QMap< QString, QgsFeatureIds > toMap() const
Definition: qgsgeometrycheck.h:112
QgsGeometryCheck::ChangeRemoved
@ ChangeRemoved
Something has been removed.
Definition: qgsgeometrycheck.h:145
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsGeometryCheck
This class implements a geometry check.
Definition: qgsgeometrycheck.h:92
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsGeometryCheck::configurationValue
T configurationValue(const QString &name, const QVariant &defaultValue=QVariant())
Returns the configuration value with the name, saved in the QGIS settings for this geometry check.
Definition: qgsgeometrycheck.h:235
QgsGeometryCheckContext
Base configuration for geometry checks.
Definition: qgsgeometrycheckcontext.h:32
QgsGeometryCheck::ChangeWhat
ChangeWhat
Description of a change to indicate at which level a change occurred.
Definition: qgsgeometrycheck.h:130
QgsGeometryCheck::~QgsGeometryCheck
virtual ~QgsGeometryCheck()=default
QgsGeometryCheck::LayerFeatureIds
A list of layers and feature ids for each of these layers.
Definition: qgsgeometrycheck.h:105
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:74
QgsGeometryCheck::Change::operator==
bool operator==(const QgsGeometryCheck::Change &other)
Definition: qgsgeometrycheck.h:203
SIP_INOUT
#define SIP_INOUT
Definition: qgis_sip.h:71
QgsGeometryCheck::mContext
const QgsGeometryCheckContext * mContext
Definition: qgsgeometrycheck.h:358
qgsvectorlayer.h
QgsGeometryCheck::Change::vidx
QgsVertexId vidx
The index of the part / ring / vertex, depending on.
Definition: qgsgeometrycheck.h:202
qgsgeometry.h
QgsGeometryCheck::ChangePart
@ ChangePart
This change happens on part level.
Definition: qgsgeometrycheck.h:132
QgsGeometryCheck::ChangeRing
@ ChangeRing
This change happens on ring level.
Definition: qgsgeometrycheck.h:133
QgsGeometryCheck::Change::type
QgsGeometryCheck::ChangeType type
What action this change performs.
Definition: qgsgeometrycheck.h:197
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
qgsgeometrycheckerutils.h
QgsGeometryCheck::CheckType
CheckType
The type of a check.
Definition: qgsgeometrycheck.h:155
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsabstractgeometry.h:1059
qgssettings.h
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsGeometryCheck::Change::Change
Change()=default
QgsGeometryCheck::FeatureCheck
@ FeatureCheck
The check controls geometries as a whole.
Definition: qgsgeometrycheck.h:157
QgsGeometryCheckError
This represents an error reported by a geometry check.
Definition: qgsgeometrycheckerror.h:36
qgsgeometrycheckresolutionmethod.h
QgsGeometryCheck::LayerFeatureIds::LayerFeatureIds
LayerFeatureIds()=default
QgsFeaturePool
A feature pool is based on a vector layer and caches features.
Definition: qgsfeaturepool.h:38