Class: QgsGeometryCheck¶
- class qgis.analysis.QgsGeometryCheck¶
Bases:
sip.wrapper
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
A new subclass of
QgsGeometryCheck
needs to be written and at least the following abstract methods need to be implemented:compatibleGeometryTypes()
: A list of geometry types to which this check appliesresolutionMethods()
: A list of names for (automated) resolution methods that can be used to fix errors of this typedescription()
: A description for the geometry check.id()
: A unique id for this check.checkType()
: One ofQgsGeometryCheck
.LayerCheck,QgsGeometryCheck
.FeatureCheck,:py:class:QgsGeometryCheck.FeatureNodeCheckcollectErrors()
: 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).
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
QgsGeometryCheck
instances are created and used in parallel.A new subclass of
QgsGeometryCheckFactory
needs to be written and at least the following abstract methods need to be implemented:QgsGeometryCheckFactory.createGeometryCheck()
: Needs to return a new subclassedQgsGeometryCheck
object that has been written in the previous step.QgsGeometryCheckFactory.id()
: A unique id for this geometry check.QgsGeometryCheckFactory.description()
: A description for this geometry check that can be presented to the user for more explanation.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.QgsGeometryCheckFactory.flags()
: Returns additional flags for a geometry check. If unsure returnQgsGeometryCheck
.AvailableInValidation.QgsGeometryCheckFactory.checkType()
: Returns the type of this geometry check.
Finally the geometry check factory needs to be registered in QGIS, so the system is aware of the available geometry checks.
# Make sure you always keep a checkFactory = MyGeometryCheckFactory() QgsAnalysis.geometryCheckRegistry().registerGeometryCheck(checkFactory)
Note
This class is a technology preview and unstable API.
New in version 3.4.
QgsGeometryCheck(context:
QgsGeometryCheckContext
, configuration: Dict[str, Any]) Create a new geometry check.QgsGeometryCheck(
QgsGeometryCheck
)Methods
Returns a list of available resolution methods.
Returns the check type.
The main worker method.
A list of geometry types for which this check can be performed.
Returns the context
Returns a human readable description for this check.
Flags for this geometry check.
Returns an id for this check.
Returns if this geometry check is compatible with
layer
. By default it checks for the geometry type in ``compatibleGeometryTypes``().Will be run in the main thread before collectErrors is called (which may be run from a background thread).
Returns a list of descriptions for available resolutions for errors.
Attributes
- AvailableInValidation = 2¶
- class Change¶
Bases:
sip.wrapper
QgsGeometryCheck.Change(_what: QgsGeometryCheck.ChangeWhat, _type: QgsGeometryCheck.ChangeType, _vidx:
QgsVertexId
= QgsVertexId()) Create a new ChangeQgsGeometryCheck.Change(QgsGeometryCheck.Change)
- type¶
- vidx¶
- what¶
- ChangeAdded = 0¶
- ChangeChanged = 2¶
- ChangeFeature = 0¶
- ChangeNode = 3¶
- ChangePart = 1¶
- ChangeRemoved = 1¶
- ChangeRing = 2¶
- class ChangeType¶
Bases:
int
- class ChangeWhat¶
Bases:
int
- class CheckType¶
Bases:
int
- FeatureCheck = 1¶
- FeatureNodeCheck = 0¶
- class Flag¶
Bases:
int
- class Flags¶
- class Flags(Union[QgsGeometryCheck.Flags, QgsGeometryCheck.Flag])
- class Flags(QgsGeometryCheck.Flags)
Bases:
sip.wrapper
- baseClass¶
alias of
QgsGeometryCheck
- LayerCheck = 2¶
- class LayerFeatureIds¶
- class LayerFeatureIds(QgsGeometryCheck.LayerFeatureIds)
Bases:
sip.wrapper
- availableResolutionMethods(self) List[QgsGeometryCheckResolutionMethod] ¶
Returns a list of available resolution methods.
New in version 3.12.
- Return type
- checkType(self) QgsGeometryCheck.CheckType ¶
Returns the check type.
New in version 3.4.
- Return type
- collectErrors(self, featurePools: object, errors: Iterable[QgsGeometryCheckError], messages: Iterable[str], feedback: QgsFeedback, ids: QgsGeometryCheck.LayerFeatureIds = QgsGeometryCheck.LayerFeatureIds()) Tuple[List[QgsGeometryCheckError], List[str]] ¶
The main worker method. Check all features available from
featurePools
and write errors found toerrors
. Other status messages can be written tomessages
. Progress should be reported tofeedback
. Only features and layers listed inids
should be checked.New in version 3.4.
- Parameters
featurePools (object) –
errors (Iterable[QgsGeometryCheckError]) –
messages (Iterable[str]) –
feedback (QgsFeedback) –
ids (QgsGeometryCheck.LayerFeatureIds = QgsGeometryCheck.LayerFeatureIds()) –
- Return type
Tuple[List[QgsGeometryCheckError], List[str]]
- compatibleGeometryTypes(self) object ¶
A list of geometry types for which this check can be performed.
New in version 3.4.
- Return type
object
- context(self) QgsGeometryCheckContext ¶
Returns the context
New in version 3.4.
- Return type
- description(self) str ¶
Returns a human readable description for this check.
New in version 3.4.
- Return type
str
- flags(self) QgsGeometryCheck.Flags ¶
Flags for this geometry check.
- Return type
- id(self) str ¶
Returns an id for this check.
New in version 3.4.
- Return type
str
- isCompatible(self, layer: QgsVectorLayer) bool ¶
Returns if this geometry check is compatible with
layer
. By default it checks for the geometry type in ``compatibleGeometryTypes``().New in version 3.4.
- Parameters
layer (QgsVectorLayer) –
- Return type
bool
- prepare(self, context: QgsGeometryCheckContext, configuration: Dict[str, Any])¶
Will be run in the main thread before collectErrors is called (which may be run from a background thread).
New in version 3.10.
- Parameters
context (QgsGeometryCheckContext) –
configuration (Dict[str) –
- resolutionMethods(self) List[str] ¶
Returns a list of descriptions for available resolutions for errors. The index will be passed as
method
tofixError()
.Deprecated since version QGIS: 3.12 use
availableResolutionMethods()
insteadNew in version 3.4.
- Return type
List[str]
- staticMetaObject = <PyQt5.QtCore.QMetaObject object>¶