QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 <limits>
20
21#include "qgis_analysis.h"
22#include "qgsfeature.h"
23#include "qgsgeometry.h"
26#include "qgssettings.h"
27#include "qgsvectorlayer.h"
28
29#include <QApplication>
30#include <QPointer>
31#include <QStringList>
32
34class QgsFeaturePool;
35
92class ANALYSIS_EXPORT QgsGeometryCheck
93{
94 Q_GADGET
95
96 public:
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
136
148
160
162 enum class Result : int
163 {
164 Success = 0,
165 Canceled = 1,
166 DuplicatedUniqueId = 2,
167 InvalidReferenceLayer = 3,
168 GeometryOverlayError = 4
169 };
170
174 enum Flag SIP_ENUM_BASETYPE( IntFlag )
175 {
177 };
178 Q_DECLARE_FLAGS( Flags, Flag )
179 Q_FLAG( Flags )
180
181
186 struct Change
187 {
188 Change() = default;
189
194 : what( _what )
195 , type( _type )
196 , vidx( _vidx )
197 {}
198
203
208
213
214 // TODO c++20 - replace with = default
215 bool operator==( const QgsGeometryCheck::Change &other ) const
216 {
217 return what == other.what && type == other.type && vidx == other.vidx;
218 }
219
220 bool operator!=( const QgsGeometryCheck::Change &other ) const
221 {
222 return !( *this == other );
223 }
224 };
225
230 typedef QMap<QString, QMap<QgsFeatureId, QList<QgsGeometryCheck::Change>>> Changes;
231
235 QgsGeometryCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
236 virtual ~QgsGeometryCheck() = default;
237
243 virtual void prepare( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
244
245#ifndef SIP_RUN
246
251 template<class T>
252 T configurationValue( const QString &name, const QVariant &defaultValue = QVariant() )
253 {
254 return mConfiguration.value( name, QgsSettings().value( "/geometry_checker/" + id() + "/" + name, defaultValue ) ).value<T>();
255 }
256#endif
257
264 virtual bool isCompatible( QgsVectorLayer *layer ) const;
265
271 virtual QList<Qgis::GeometryType> compatibleGeometryTypes() const = 0;
272
276 virtual QgsGeometryCheck::Flags flags() const;
277
287 virtual Result collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors SIP_INOUT, QStringList &messages SIP_INOUT, QgsFeedback *feedback, const LayerFeatureIds &ids = QgsGeometryCheck::LayerFeatureIds() ) const;
288
297 virtual void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes SIP_INOUT ) const SIP_SKIP;
298
304 virtual QList<QgsGeometryCheckResolutionMethod> availableResolutionMethods() const;
305
313 Q_DECL_DEPRECATED virtual QStringList resolutionMethods() const SIP_DEPRECATED;
314
320 virtual QString description() const = 0;
321
327 virtual QString id() const = 0;
328
334 virtual CheckType checkType() const = 0;
335
341 const QgsGeometryCheckContext *context() const { return mContext; }
342
343 protected:
350 QMap<QString, QgsFeatureIds> allLayerFeatureIds( const QMap<QString, QgsFeaturePool *> &featurePools ) const SIP_SKIP;
351
358 void replaceFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, QgsAbstractGeometry *newPartGeom, Changes &changes ) const SIP_SKIP;
359
366 void deleteFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, Changes &changes ) const SIP_SKIP;
367
374 void deleteFeatureGeometryRing( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, int ringIdx, Changes &changes ) const SIP_SKIP;
375
377 QVariantMap mConfiguration;
378
385 double scaleFactor( const QPointer<QgsVectorLayer> &layer ) const SIP_SKIP;
386
393 Result checkUniqueId( const QgsGeometryCheckerUtils::LayerFeature layerFeature, QMap< QString, QSet<QVariant> > &uniqueIds ) const SIP_SKIP;
394};
395
396#endif // QGS_GEOMETRY_CHECK_H
Abstract base class for all geometries.
A feature pool is based on a vector layer and caches features.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Base configuration for geometry checks.
This represents an error reported by a geometry check.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
QFlags< Flag > Flags
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.
virtual QList< QgsGeometryCheckResolutionMethod > availableResolutionMethods() const
Returns a list of available resolution methods.
virtual Q_DECL_DEPRECATED QStringList resolutionMethods() const
Returns a list of descriptions for available resolutions for errors.
const QgsGeometryCheckContext * mContext
ChangeWhat
Description of a change to indicate at which level a change occurred.
@ ChangeNode
This change happens on node level.
@ ChangeRing
This change happens on ring level.
@ ChangeFeature
This change happens on feature level.
@ ChangePart
This change happens on part level.
Flag
Flags for geometry checks.
@ AvailableInValidation
This geometry check should be available in layer validation on the vector layer peroperties.
CheckType
The type of a check.
@ LayerCheck
The check controls a whole layer (topology checks).
@ FeatureNodeCheck
The check controls individual nodes.
@ FeatureCheck
The check controls geometries as a whole.
Result checkUniqueId(const QgsGeometryCheckerUtils::LayerFeature layerFeature, QMap< QString, QSet< QVariant > > &uniqueIds) const
Checks that there are no duplicated unique IDs.
Result
Result of the geometry checker operation.
QVariantMap mConfiguration
ChangeType
Description of the type of a change.
@ ChangeChanged
Something has been updated.
@ ChangeAdded
Something has been added.
@ ChangeRemoved
Something has been removed.
virtual CheckType checkType() const =0
Returns the check type.
virtual ~QgsGeometryCheck()=default
virtual QString description() const =0
Returns a human readable description for this check.
double scaleFactor(const QPointer< QgsVectorLayer > &layer) const
Determines the scale factor of a layer to the map coordinate reference system.
virtual QgsGeometryCheck::Flags flags() const
Flags for this geometry check.
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.
virtual QList< Qgis::GeometryType > compatibleGeometryTypes() const =0
A list of geometry types for which this check can be performed.
QgsGeometryCheck(const QgsGeometryCheckContext *context, const QVariantMap &configuration)
Create a new geometry check.
const QgsGeometryCheckContext * context() const
Returns the context.
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 t...
A layer feature combination to uniquely identify and access a feature in a set of layers.
Stores settings for use within QGIS.
Definition qgssettings.h:65
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_INOUT
Definition qgis_sip.h:79
void CPL_STDCALL collectErrors(CPLErr, int, const char *msg)
Descripts a change to fix a geometry.
Change(QgsGeometryCheck::ChangeWhat _what, QgsGeometryCheck::ChangeType _type, QgsVertexId _vidx=QgsVertexId())
Create a new Change.
QgsGeometryCheck::ChangeType type
What action this change performs.
QgsVertexId vidx
The index of the part / ring / vertex, depending on.
QgsGeometryCheck::ChangeWhat what
What level this change affects.
bool operator==(const QgsGeometryCheck::Change &other) const
bool operator!=(const QgsGeometryCheck::Change &other) const
A list of layers and feature ids for each of these layers.
QMap< QString, QgsFeatureIds > ids
QMap< QString, QgsFeatureIds > toMap() const
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30