/
qgssinglegeometrycheck.h
164 lines (137 loc) · 5.12 KB
/
qgssinglegeometrycheck.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/***************************************************************************
qgssinglegeometrycheck.h
--------------------------------------
Date : 6.9.2018
Copyright : (C) 2018 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSSINGLEGEOMETRYCHECK_H
#define QGSSINGLEGEOMETRYCHECK_H
#define SIP_NO_FILE
#include <QList>
#include <QCoreApplication>
#include "qgsgeometry.h"
#include "qgsgeometrycheck.h"
#include "qgis_analysis.h"
class QgsFeature;
class QgsSingleGeometryCheck;
/**
* \ingroup analysis
*
* An error from a QgsSingleGeometryCheck.
*
* \since QGIS 3.4
*/
class ANALYSIS_EXPORT QgsSingleGeometryCheckError
{
public:
QgsSingleGeometryCheckError( const QgsSingleGeometryCheck *check, const QgsGeometry &geometry, const QgsGeometry &errorLocation, const QgsVertexId &vertexId = QgsVertexId() )
: mCheck( check )
, mGeometry( geometry )
, mErrorLocation( errorLocation )
, mVertexId( vertexId )
{}
virtual ~QgsSingleGeometryCheckError() = default;
/**
* Update this error with the information from \other.
* Will be used to update existing errors whenever they are re-checked.
*/
virtual void update( const QgsSingleGeometryCheckError *other );
/**
* Check if this error is equal to \a other.
* Is reimplemented by subclasses with additional information, comparison
* of base information is done in parent class.
*/
virtual bool isEqual( const QgsSingleGeometryCheckError *other ) const;
/**
* Apply a list of \a changes.
*/
virtual bool handleChanges( const QList<QgsGeometryCheck::Change> &changes );
/**
* A human readable description of this error.
*/
virtual QString description() const;
/**
* The check that created this error.
*
* \since QGIS 3.4
*/
const QgsSingleGeometryCheck *check() const;
/**
* The exact location of the error.
*
* \since QGIS 3.4
*/
QgsGeometry errorLocation() const;
/**
* The vertex id of the error. May be invalid depending on the check.
*
* \since QGIS 3.4
*/
QgsVertexId vertexId() const;
protected:
const QgsSingleGeometryCheck *mCheck = nullptr;
QgsGeometry mGeometry;
QgsGeometry mErrorLocation;
QgsVertexId mVertexId;
};
/**
* \ingroup analysis
*
* Wraps a QgsSingleGeometryError into a standard QgsGeometryCheckError.
* The single error can be obtained via singleError.
*
* \since QGIS 3.4
*/
class ANALYSIS_EXPORT QgsGeometryCheckErrorSingle : public QgsGeometryCheckError
{
public:
QgsGeometryCheckErrorSingle( QgsSingleGeometryCheckError *singleError, const QgsGeometryCheckerUtils::LayerFeature &layerFeature );
/**
* The underlying single error.
*/
QgsSingleGeometryCheckError *singleError() const;
bool handleChanges( const QgsGeometryCheck::Changes &changes ) override;
private:
QgsSingleGeometryCheckError *mError = nullptr;
};
/**
* \ingroup analysis
*
* Base class for geometry checks for a single geometry without any context of the layer or other layers in the project.
* Classic examples are validity checks like self-intersection.
*
* Subclasses need to implement the processGeometry method.
*
* \since QGIS 3.4
*/
class ANALYSIS_EXPORT QgsSingleGeometryCheck : public QgsGeometryCheck
{
public:
QgsSingleGeometryCheck( CheckType checkType, const QList<QgsWkbTypes::GeometryType> &compatibleGeometryTypes, QgsGeometryCheckerContext *context );
void collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter = nullptr, const QMap<QString, QgsFeatureIds> &ids = QMap<QString, QgsFeatureIds>() ) const final;
/**
* Check the \a geometry for errors. It may make use of \a configuration options.
*
* Returns a list of QgsSingleGeometryCheckErrors, ownership is transferred to the caller.
* An empty list is returned for geometries without errors.
*
* \since QGIS 3.4
*/
virtual QList<QgsSingleGeometryCheckError *> processGeometry( const QgsGeometry &geometry, const QVariantMap &configuration ) const = 0;
private:
/**
* Converts a QgsSingleGeometryCheckError to a QgsGeometryCheckErrorSingle.
*
* \since QGIS 3.4
*/
QgsGeometryCheckErrorSingle *convertToGeometryCheckError( QgsSingleGeometryCheckError *singleGeometryCheckError, const QgsGeometryCheckerUtils::LayerFeature &layerFeature ) const;
};
#endif // QGSSINGLEGEOMETRYCHECK_H