QGIS API Documentation  3.6.0-Noosa (5873452)
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. More...
 
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...
 

Public Member Functions

 QgsGeometryCheck (const QgsGeometryCheckContext *context, const QVariantMap &configuration)
 Create a new geometry check. More...
 
virtual ~QgsGeometryCheck ()=default
 
virtual CheckType checkType () const =0
 Returns the check type. More...
 
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. More...
 
virtual QList< QgsWkbTypes::GeometryTypecompatibleGeometryTypes () const =0
 A list of geometry types for which this check can be performed. More...
 
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. More...
 
const QgsGeometryCheckContextcontext () const
 Returns the context. More...
 
virtual QString description () const =0
 Returns a human readable description for this check. More...
 
virtual void fixError (const QMap< QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap< QString, int > &mergeAttributeIndices, Changes &changes) const
 Fix the error error with the specified method. More...
 
virtual QgsGeometryCheck::Flags flags () const
 Flags for this geometry check. More...
 
virtual QString id () const =0
 Returns an id for this check. More...
 
virtual bool isCompatible (QgsVectorLayer *layer) const
 Returns if this geometry check is compatible with layer. More...
 
virtual QStringList resolutionMethods () const =0
 Returns a list of descriptions for available resolutions for errors. More...
 

Protected Member Functions

QMap< QString, QgsFeatureIdsallLayerFeatureIds (const QMap< QString, QgsFeaturePool *> &featurePools) const
 Returns all layers and feature ids. More...
 
void deleteFeatureGeometryPart (const QMap< QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, Changes &changes) const
 Deletes a part of a feature geometry. More...
 
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. More...
 
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. More...
 
double scaleFactor (const QPointer< QgsVectorLayer > &layer) const
 Determines the scale factor of a layer to the map coordinate reference system. More...
 

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
checkFactory = MyGeometryCheckFactory()
QgsAnalysis.geometryCheckRegistry().registerGeometryCheck(checkFactory)
Note
This class is a technology preview and unstable API.
Since
QGIS 3.4

Definition at line 125 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 248 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 177 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 164 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 189 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 199 of file qgsgeometrycheck.h.

Constructor & Destructor Documentation

◆ QgsGeometryCheck()

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

Create a new geometry check.

Definition at line 29 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 53 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 QgsSingleGeometryCheck, QgsGeometryOverlapCheck, QgsGeometryGapCheck, QgsGeometryDuplicateCheck, QgsGeometryContainedCheck, QgsGeometryMissingVertexCheck, QgsGeometryAngleCheck, QgsGeometryAreaCheck, QgsGeometryFollowBoundariesCheck, QgsGeometryLineLayerIntersectionCheck, QgsGeometrySegmentLengthCheck, QgsGeometryDangleCheck, QgsGeometryLineIntersectionCheck, QgsGeometryPointCoveredByLineCheck, QgsGeometryPointInPolygonCheck, QgsGeometryDegeneratePolygonCheck, QgsGeometryDuplicateNodesCheck, and QgsGeometryHoleCheck.

◆ compatibleGeometryTypes()

virtual QList<QgsWkbTypes::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 263 of file qgsgeometrycheck.h.

◆ context()

const QgsGeometryCheckContext* QgsGeometryCheck::context ( ) const
inline

Returns the context.

Since
QGIS 3.4

Definition at line 339 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 86 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 113 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 QgsGeometryOverlapCheck, QgsGeometryGapCheck, QgsGeometrySelfIntersectionCheck, and QgsGeometryMissingVertexCheck.

Definition at line 39 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 34 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 63 of file qgsgeometrycheck.cpp.

◆ resolutionMethods()

virtual QStringList QgsGeometryCheck::resolutionMethods ( ) const
pure 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 142 of file qgsgeometrycheck.cpp.

Member Data Documentation

◆ mConfiguration

QVariantMap QgsGeometryCheck::mConfiguration
protected

Definition at line 376 of file qgsgeometrycheck.h.

◆ mContext

const QgsGeometryCheckContext* QgsGeometryCheck::mContext
protected

Definition at line 375 of file qgsgeometrycheck.h.


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