QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsGeometryCheck Class Referenceabstract

This class implements a geometry check. More...

#include <qgsgeometrycheck.h>

Inheritance diagram for QgsGeometryCheck:
Inheritance graph
[legend]

Classes

struct  Change
 Descripts a change to fix a geometry. More...
 
struct  LayerFeatureIds
 A list of layers and feature ids for each of these layers. More...
 

Public Types

typedef QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
 A collection of changes.
 
enum  ChangeType { ChangeAdded , ChangeRemoved , ChangeChanged }
 Description of the type of a change. More...
 
enum  ChangeWhat { ChangeFeature , ChangePart , ChangeRing , ChangeNode }
 Description of a change to indicate at which level a change occurred. More...
 
enum  CheckType { FeatureNodeCheck , FeatureCheck , LayerCheck }
 The type of a check. More...
 
enum  Flag { AvailableInValidation = 1 << 1 }
 Flags for geometry checks. More...
 
typedef QFlags< FlagFlags
 

Public Member Functions

 QgsGeometryCheck (const QgsGeometryCheckContext *context, const QVariantMap &configuration)
 Create a new geometry check.
 
virtual ~QgsGeometryCheck ()=default
 
virtual QList< QgsGeometryCheckResolutionMethodavailableResolutionMethods () const
 Returns a list of available resolution methods.
 
virtual CheckType checkType () const =0
 Returns the check type.
 
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.
 
virtual QList< Qgis::GeometryTypecompatibleGeometryTypes () const =0
 A list of geometry types for which this check can be performed.
 
template<class 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.
 
const QgsGeometryCheckContextcontext () const
 Returns the context.
 
virtual QString description () const =0
 Returns a human readable description for this 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 QgsGeometryCheck::Flags flags () const
 Flags for this geometry check.
 
virtual QString id () const =0
 Returns an id for this check.
 
virtual bool isCompatible (QgsVectorLayer *layer) const
 Returns if this geometry check is compatible with layer.
 
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 thread).
 
virtual Q_DECL_DEPRECATED QStringList resolutionMethods () const
 Returns a list of descriptions for available resolutions for errors.
 

Protected Member Functions

QMap< QString, QgsFeatureIdsallLayerFeatureIds (const QMap< QString, QgsFeaturePool * > &featurePools) const
 Returns all layers and feature ids.
 
void deleteFeatureGeometryPart (const QMap< QString, QgsFeaturePool * > &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, Changes &changes) const
 Deletes a part of a feature geometry.
 
void deleteFeatureGeometryRing (const QMap< QString, QgsFeaturePool * > &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, int ringIdx, Changes &changes) const
 Deletes a ring in a feature geometry.
 
void replaceFeatureGeometryPart (const QMap< QString, QgsFeaturePool * > &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, QgsAbstractGeometry *newPartGeom, Changes &changes) const
 Replaces a part in a feature geometry.
 
double scaleFactor (const QPointer< QgsVectorLayer > &layer) const
 Determines the scale factor of a layer to the map coordinate reference system.
 

Protected Attributes

QVariantMap mConfiguration
 
const QgsGeometryCheckContextmContext
 

Detailed Description

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 QgsGeometryCheck needs to be written and at least the following abstract methods need to be implemented:

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 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:

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.

# Make sure you always keep a reference
checkFactory = MyGeometryCheckFactory()
QgsAnalysis.geometryCheckRegistry().registerGeometryCheck(checkFactory)
static QgsGeometryCheckRegistry * geometryCheckRegistry()
Returns the global geometry checker registry, used for managing all geometry check factories.
Note
This class is a technology preview and unstable API.
Since
QGIS 3.4

Definition at line 91 of file qgsgeometrycheck.h.

Member Typedef Documentation

◆ Changes

typedef QMap<QString, QMap<QgsFeatureId, QList<QgsGeometryCheck::Change> > > QgsGeometryCheck::Changes

A collection of changes.

Grouped by layer id and feature id.

Definition at line 219 of file qgsgeometrycheck.h.

◆ Flags

typedef QFlags< Flag > QgsGeometryCheck::Flags

Definition at line 167 of file qgsgeometrycheck.h.

Member Enumeration Documentation

◆ ChangeType

Description of the type of a change.

Since
Python bindings since QGIS 3.4
Enumerator
ChangeAdded 

Something has been added.

ChangeRemoved 

Something has been removed.

ChangeChanged 

Something has been updated.

Definition at line 141 of file qgsgeometrycheck.h.

◆ ChangeWhat

Description of a change to indicate at which level a change occurred.

Since
Python bindings since QGIS 3.4
Enumerator
ChangeFeature 

This change happens on feature level.

ChangePart 

This change happens on part level.

ChangeRing 

This change happens on ring level.

ChangeNode 

This change happens on node level.

Definition at line 128 of file qgsgeometrycheck.h.

◆ CheckType

The type of a check.

Since
Python bindings since QGIS 3.4
Enumerator
FeatureNodeCheck 

The check controls individual nodes.

FeatureCheck 

The check controls geometries as a whole.

LayerCheck 

The check controls a whole layer (topology checks)

Definition at line 153 of file qgsgeometrycheck.h.

◆ Flag

Flags for geometry checks.

Enumerator
AvailableInValidation 

This geometry check should be available in layer validation on the vector layer peroperties.

Definition at line 163 of file qgsgeometrycheck.h.

Constructor & Destructor Documentation

◆ QgsGeometryCheck()

QgsGeometryCheck::QgsGeometryCheck ( const QgsGeometryCheckContext context,
const QVariantMap &  configuration 
)

Create a new geometry check.

Definition at line 28 of file qgsgeometrycheck.cpp.

◆ ~QgsGeometryCheck()

virtual QgsGeometryCheck::~QgsGeometryCheck ( )
virtualdefault

Member Function Documentation

◆ allLayerFeatureIds()

QMap< QString, QgsFeatureIds > QgsGeometryCheck::allLayerFeatureIds ( const QMap< QString, QgsFeaturePool * > &  featurePools) const
protected

Returns all layers and feature ids.

Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 81 of file qgsgeometrycheck.cpp.

◆ availableResolutionMethods()

QList< QgsGeometryCheckResolutionMethod > QgsGeometryCheck::availableResolutionMethods ( ) const
virtual

Returns a list of available resolution methods.

Since
QGIS 3.12

Reimplemented in QgsGeometryGapCheck.

Definition at line 58 of file qgsgeometrycheck.cpp.

◆ checkType()

virtual CheckType QgsGeometryCheck::checkType ( ) const
pure virtual

◆ collectErrors()

virtual void QgsGeometryCheck::collectErrors ( const QMap< QString, QgsFeaturePool * > &  featurePools,
QList< QgsGeometryCheckError * > &  errors,
QStringList &  messages,
QgsFeedback feedback,
const LayerFeatureIds ids = QgsGeometryCheck::LayerFeatureIds() 
) const
pure virtual

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.

Since
QGIS 3.4

Implemented in QgsGeometryAngleCheck, QgsGeometryAreaCheck, QgsGeometryContainedCheck, QgsGeometryDangleCheck, QgsGeometryDegeneratePolygonCheck, QgsGeometryDuplicateCheck, QgsGeometryDuplicateNodesCheck, QgsGeometryFollowBoundariesCheck, QgsGeometryGapCheck, QgsGeometryHoleCheck, QgsGeometryLineIntersectionCheck, QgsGeometryLineLayerIntersectionCheck, QgsGeometryMissingVertexCheck, QgsGeometryOverlapCheck, QgsGeometryPointCoveredByLineCheck, QgsGeometryPointInPolygonCheck, QgsGeometrySegmentLengthCheck, and QgsSingleGeometryCheck.

◆ compatibleGeometryTypes()

virtual QList< Qgis::GeometryType > QgsGeometryCheck::compatibleGeometryTypes ( ) const
pure virtual

◆ configurationValue()

template<class T >
T QgsGeometryCheck::configurationValue ( const QString &  name,
const QVariant &  defaultValue = QVariant() 
)
inline

Returns the configuration value with the name, saved in the QGIS settings for this geometry check.

If no configuration could be found, defaultValue is returned.

Definition at line 241 of file qgsgeometrycheck.h.

◆ context()

const QgsGeometryCheckContext * QgsGeometryCheck::context ( ) const
inline

Returns the context.

Since
QGIS 3.4

Definition at line 328 of file qgsgeometrycheck.h.

◆ deleteFeatureGeometryPart()

void QgsGeometryCheck::deleteFeatureGeometryPart ( const QMap< QString, QgsFeaturePool * > &  featurePools,
const QString &  layerId,
QgsFeature feature,
int  partIdx,
Changes changes 
) const
protected

Deletes a part of a feature geometry.

Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 112 of file qgsgeometrycheck.cpp.

◆ deleteFeatureGeometryRing()

void QgsGeometryCheck::deleteFeatureGeometryRing ( const QMap< QString, QgsFeaturePool * > &  featurePools,
const QString &  layerId,
QgsFeature feature,
int  partIdx,
int  ringIdx,
Changes changes 
) const
protected

Deletes a ring in a feature geometry.

Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 139 of file qgsgeometrycheck.cpp.

◆ description()

virtual QString QgsGeometryCheck::description ( ) const
pure virtual

◆ fixError()

void QgsGeometryCheck::fixError ( const QMap< QString, QgsFeaturePool * > &  featurePools,
QgsGeometryCheckError error,
int  method,
const QMap< QString, int > &  mergeAttributeIndices,
QgsGeometryCheck::Changes changes 
) const
virtual

◆ flags()

QgsGeometryCheck::Flags QgsGeometryCheck::flags ( ) const
virtual

Flags for this geometry check.

Reimplemented in QgsGeometryGapCheck, QgsGeometryMissingVertexCheck, QgsGeometryOverlapCheck, and QgsGeometrySelfIntersectionCheck.

Definition at line 44 of file qgsgeometrycheck.cpp.

◆ id()

virtual QString QgsGeometryCheck::id ( ) const
pure virtual

◆ isCompatible()

bool QgsGeometryCheck::isCompatible ( QgsVectorLayer layer) const
virtual

Returns if this geometry check is compatible with layer.

By default it checks for the geometry type in compatibleGeometryTypes().

Since
QGIS 3.4

Definition at line 39 of file qgsgeometrycheck.cpp.

◆ prepare()

void QgsGeometryCheck::prepare ( const QgsGeometryCheckContext context,
const QVariantMap &  configuration 
)
virtual

Will be run in the main thread before collectErrors() is called (which may be run from a background thread).

Since
QGIS 3.10

Reimplemented in QgsGeometryGapCheck.

Definition at line 33 of file qgsgeometrycheck.cpp.

◆ replaceFeatureGeometryPart()

void QgsGeometryCheck::replaceFeatureGeometryPart ( const QMap< QString, QgsFeaturePool * > &  featurePools,
const QString &  layerId,
QgsFeature feature,
int  partIdx,
QgsAbstractGeometry newPartGeom,
Changes changes 
) const
protected

Replaces a part in a feature geometry.

Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 91 of file qgsgeometrycheck.cpp.

◆ resolutionMethods()

QStringList QgsGeometryCheck::resolutionMethods ( ) const
virtual

◆ scaleFactor()

double QgsGeometryCheck::scaleFactor ( const QPointer< QgsVectorLayer > &  layer) const
protected

Determines the scale factor of a layer to the map coordinate reference system.

Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 166 of file qgsgeometrycheck.cpp.

Member Data Documentation

◆ mConfiguration

QVariantMap QgsGeometryCheck::mConfiguration
protected

Definition at line 364 of file qgsgeometrycheck.h.

◆ mContext

const QgsGeometryCheckContext* QgsGeometryCheck::mContext
protected

Definition at line 363 of file qgsgeometrycheck.h.


The documentation for this class was generated from the following files: