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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/vector/geometry_checker/qgsgeometrycheck.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
class QgsGeometryCheck
{
%Docstring(signature="appended")
This class implements a geometry check.
Geometry checks run over a set of features and can detect errors like
topological or other issues which are reported in the geometry
validation panel in QGIS and help a user to create valid geometries.
Implementing a custom geometry check consists of the following parts
Writing the check
-----------------------------------------------
A new subclass of :py:class:`QgsGeometryCheck` needs to be written and
at least the following abstract methods need to be implemented:
- :py:func:`~compatibleGeometryTypes`: A list of geometry types to which
this check applies
- :py:func:`~availableResolutionMethods`: A list of resolution methods
that can be used to fix errors of this type
- :py:func:`~description`: A description for the geometry check.
- :py:func:`~id`: A unique id for this check.
- :py:func:`~checkType`: One of :py:class:`QgsGeometryCheck`.LayerCheck,
:py:class:`QgsGeometryCheck`.FeatureCheck,
:py:class:`QgsGeometryCheck`.FeatureNodeCheck
- :py:func:`~collectErrors`: This method will be called to validate
geometries. All geometries which should be validated are passed into
this method with the parameter ids and should be retrieved from the
available featurePools to make use of caching. New errors should be
appended to the error list and other message strings to messages. The
method needs to return a tuple (errors, messages).
Creating a geometry check factory
---------------------------------------------------------------
A Geometry check factory manages meta information for checks. There will
always be one single geometry check factory created per check type, but
it's possible that multiple :py:class:`QgsGeometryCheck` instances are
created and used in parallel.
A new subclass of :py:class:`QgsGeometryCheckFactory` needs to be
written and at least the following abstract methods need to be
implemented:
- :py:func:`QgsGeometryCheckFactory.createGeometryCheck()`: Needs to
return a new subclassed :py:class:`QgsGeometryCheck` object that has
been written in the previous step.
- :py:func:`QgsGeometryCheckFactory.id()`: A unique id for this geometry
check.
- :py:func:`QgsGeometryCheckFactory.description()`: A description for
this geometry check that can be presented to the user for more
explanation.
- :py:func:`QgsGeometryCheckFactory.isCompatible()`: Returns a boolean
that determines if this check is available for a given layer. This
often checks for the geometry type of the layer.
- :py:func:`QgsGeometryCheckFactory.flags()`: Returns additional flags
for a geometry check. If unsure return
:py:class:`QgsGeometryCheck`.AvailableInValidation.
- :py:func:`QgsGeometryCheckFactory.checkType()`: Returns the type of
this geometry check.
Registering the geometry check
------------------------------------------------------------
Finally the geometry check factory needs to be registered in QGIS, so
the system is aware of the available geometry checks.
.. code-block:: python
# Make sure you always keep a reference
checkFactory = MyGeometryCheckFactory()
QgsAnalysis.geometryCheckRegistry().registerGeometryCheck(checkFactory)
.. note::
This class is a technology preview and unstable API.
.. versionadded:: 3.4
%End
%TypeHeaderCode
#include "qgsgeometrycheck.h"
%End
public:
static const QMetaObject staticMetaObject;
public:
struct LayerFeatureIds
{
LayerFeatureIds();
};
enum ChangeWhat /BaseType=IntEnum/
{
ChangeFeature,
ChangePart,
ChangeRing,
ChangeNode
};
enum ChangeType /BaseType=IntEnum/
{
ChangeAdded,
ChangeRemoved,
ChangeChanged
};
enum CheckType /BaseType=IntEnum/
{
FeatureNodeCheck,
FeatureCheck,
LayerCheck
};
enum Flag /BaseType=IntEnum/
{
AvailableInValidation
};
typedef QFlags<QgsGeometryCheck::Flag> Flags;
struct Change
{
Change();
Change( QgsGeometryCheck::ChangeWhat _what, QgsGeometryCheck::ChangeType _type, QgsVertexId _vidx = QgsVertexId() );
%Docstring
Create a new Change
%End
QgsGeometryCheck::ChangeWhat what;
QgsGeometryCheck::ChangeType type;
QgsVertexId vidx;
bool operator==( const QgsGeometryCheck::Change &other ) const;
bool operator!=( const QgsGeometryCheck::Change &other ) const;
};
typedef QMap<QString, QMap<QgsFeatureId, QList<QgsGeometryCheck::Change>>> Changes;
QgsGeometryCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
%Docstring
Create a new geometry check.
%End
virtual ~QgsGeometryCheck();
virtual void prepare( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
%Docstring
Will be run in the main thread before
:py:func:`~QgsGeometryCheck.collectErrors` is called (which may be run
from a background thread).
.. versionadded:: 3.10
%End
virtual bool isCompatible( QgsVectorLayer *layer ) const;
%Docstring
Returns if this geometry check is compatible with ``layer``. By default
it checks for the geometry type in
:py:func:`~QgsGeometryCheck.compatibleGeometryTypes`.
.. versionadded:: 3.4
%End
virtual QList<Qgis::GeometryType> compatibleGeometryTypes() const = 0;
%Docstring
A list of geometry types for which this check can be performed.
.. versionadded:: 3.4
%End
virtual QgsGeometryCheck::Flags flags() const;
%Docstring
Flags for this geometry check.
%End
virtual void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors /In,Out/, QStringList &messages /In,Out/, QgsFeedback *feedback, const LayerFeatureIds &ids = QgsGeometryCheck::LayerFeatureIds() ) const = 0;
%Docstring
The main worker method. Check all features available from
``featurePools`` and write errors found to ``errors``. Other status
messages can be written to ``messages``. Progress should be reported to
``feedback``. Only features and layers listed in ``ids`` should be
checked.
.. versionadded:: 3.4
%End
virtual QList<QgsGeometryCheckResolutionMethod> availableResolutionMethods() const;
%Docstring
Returns a list of available resolution methods.
.. versionadded:: 3.12
%End
virtual QStringList resolutionMethods() const /Deprecated/;
%Docstring
Returns a list of descriptions for available resolutions for errors. The
index will be passed as ``method`` to :py:func:`fixError`.
.. deprecated:: 3.12
Use :py:func:`~QgsGeometryCheck.availableResolutionMethods` instead.
.. versionadded:: 3.4
%End
virtual QString description() const = 0;
%Docstring
Returns a human readable description for this check.
.. versionadded:: 3.4
%End
virtual QString id() const = 0;
%Docstring
Returns an id for this check.
.. versionadded:: 3.4
%End
virtual CheckType checkType() const = 0;
%Docstring
Returns the check type.
.. versionadded:: 3.4
%End
const QgsGeometryCheckContext *context() const;
%Docstring
Returns the context
.. versionadded:: 3.4
%End
protected:
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/vector/geometry_checker/qgsgeometrycheck.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
|