QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsgeometryisvalidcheck.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssinglegeometrycheck.cpp
3  --------------------------------------
4 Date : 7.9.2018
5 Copyright : (C) 2018 by Matthias Kuhn
6 email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 #include "qgsfeature.h"
19 #include "qgsgeos.h"
20 #include "qgsgeometryvalidator.h"
21 
22 QgsGeometryIsValidCheck::QgsGeometryIsValidCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration )
23  : QgsSingleGeometryCheck( context, configuration )
24 {}
25 
26 QList<QgsWkbTypes::GeometryType> QgsGeometryIsValidCheck::compatibleGeometryTypes() const
27 {
28  return factoryCompatibleGeometryTypes();
29 }
30 
31 QList<QgsSingleGeometryCheckError *> QgsGeometryIsValidCheck::processGeometry( const QgsGeometry &geometry ) const
32 {
33  QVector<QgsGeometry::Error> errors;
34 
35  Qgis::GeometryValidationEngine method = Qgis::GeometryValidationEngine::QgisInternal;
37  method = Qgis::GeometryValidationEngine::Geos;
38 
39  QgsGeometryValidator validator( geometry, &errors, method );
40 
41  QObject::connect( &validator, &QgsGeometryValidator::errorFound, &validator, [ &errors ]( const QgsGeometry::Error & error )
42  {
43  errors.append( error );
44  } );
45 
46  // We are already on a thread here normally, no reason to start yet another one. Run synchronously.
47  validator.run();
48 
49  QList<QgsSingleGeometryCheckError *> result;
50  for ( const auto &error : std::as_const( errors ) )
51  {
52  QgsGeometry errorGeometry;
53  if ( error.hasWhere() )
54  errorGeometry = QgsGeometry( std::make_unique<QgsPoint>( error.where() ) );
55 
56  result << new QgsGeometryIsValidCheckError( this, geometry, errorGeometry, error.what() );
57  }
58  return result;
59 }
60 
62 {
63  return QStringList();
64 }
66 QList<QgsWkbTypes::GeometryType> QgsGeometryIsValidCheck::factoryCompatibleGeometryTypes()
67 {
69 }
70 
71 bool QgsGeometryIsValidCheck::factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP
72 {
73  return factoryCompatibleGeometryTypes().contains( layer->geometryType() );
74 }
75 
76 QString QgsGeometryIsValidCheck::factoryDescription()
77 {
78  return tr( "Is Valid" );
79 }
80 
81 QString QgsGeometryIsValidCheck::factoryId()
82 {
83  return QStringLiteral( "QgsIsValidCheck" );
84 }
85 
86 QgsGeometryCheck::Flags QgsGeometryIsValidCheck::factoryFlags()
87 {
88  return AvailableInValidation;
89 }
90 
91 QgsGeometryCheck::CheckType QgsGeometryIsValidCheck::factoryCheckType()
92 {
94 }
96 
97 QgsGeometryIsValidCheckError::QgsGeometryIsValidCheckError( const QgsSingleGeometryCheck *check, const QgsGeometry &geometry, const QgsGeometry &errorLocation, const QString &errorDescription )
98  : QgsSingleGeometryCheckError( check, geometry, errorLocation )
99  , mDescription( errorDescription )
100 {
101 
102 }
103 
105 {
106  return mDescription;
107 }
qgssettingsregistrycore.h
QgsGeometryIsValidCheckError
An error for a QgsGeometryIsValid check.
Definition: qgsgeometryisvalidcheck.h:32
QgsGeometryIsValidCheckError::QgsGeometryIsValidCheckError
QgsGeometryIsValidCheckError(const QgsSingleGeometryCheck *check, const QgsGeometry &geometry, const QgsGeometry &errorLocation, const QString &errorDescription)
Creates a new is valid check error.
Definition: qgsgeometryisvalidcheck.cpp:97
qgsfeature.h
QgsGeometry::Error
A geometry error.
Definition: qgsgeometry.h:2404
QgsGeometryCheck::FeatureNodeCheck
@ FeatureNodeCheck
The check controls individual nodes.
Definition: qgsgeometrycheck.h:156
qgsgeometryisvalidcheck.h
QgsSingleGeometryCheckError
An error from a QgsSingleGeometryCheck.
Definition: qgssinglegeometrycheck.h:39
QgsGeometryValidator::run
void run() override
Definition: qgsgeometryvalidator.cpp:280
Qgis::GeometryValidationEngine
GeometryValidationEngine
Available engines for validating geometries.
Definition: qgis.h:942
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
QgsSingleGeometryCheck
Base class for geometry checks for a single geometry without any context of the layer or other layers...
Definition: qgssinglegeometrycheck.h:149
QgsGeometry::Error::hasWhere
bool hasWhere() const
true if the location available from
Definition: qgsgeometry.cpp:4008
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsSettingsRegistryCore::settingsDigitizingValidateGeometries
static const QgsSettingsEntryInteger settingsDigitizingValidateGeometries
Settings entry digitizing validate geometries.
Definition: qgssettingsregistrycore.h:142
QgsGeometry::Error::what
QString what() const
A human readable error message containing details about the error.
Definition: qgsgeometry.cpp:3998
QgsGeometry::Error::where
QgsPointXY where() const
The coordinates at which the error is located and should be visualized.
Definition: qgsgeometry.cpp:4003
QgsGeometryIsValidCheck::compatibleGeometryTypes
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
Definition: qgsgeometryisvalidcheck.cpp:26
QgsGeometryCheckContext
Base configuration for geometry checks.
Definition: qgsgeometrycheckcontext.h:31
QgsGeometryIsValidCheck::QgsGeometryIsValidCheck
QgsGeometryIsValidCheck(const QgsGeometryCheckContext *context, const QVariantMap &configuration)
Creates a new is valid check with the provided context.
Definition: qgsgeometryisvalidcheck.cpp:22
QgsGeometryIsValidCheck::processGeometry
QList< QgsSingleGeometryCheckError * > processGeometry(const QgsGeometry &geometry) const override
Check the geometry for errors.
Definition: qgsgeometryisvalidcheck.cpp:31
QgsGeometryCheck::AvailableInValidation
@ AvailableInValidation
This geometry check should be available in layer validation on the vector layer peroperties.
Definition: qgsgeometrycheck.h:166
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsGeometryCheck::CheckType
CheckType
The type of a check.
Definition: qgsgeometrycheck.h:154
QgsGeometryIsValidCheck::resolutionMethods
Q_DECL_DEPRECATED QStringList resolutionMethods() const override
Returns a list of descriptions for available resolutions for errors.
Definition: qgsgeometryisvalidcheck.cpp:61
QgsGeometryIsValidCheckError::description
QString description() const override
A human readable description of this error.
Definition: qgsgeometryisvalidcheck.cpp:104
QgsGeometryValidator
Definition: qgsgeometryvalidator.h:31
QgsGeometryValidator::errorFound
void errorFound(const QgsGeometry::Error &error)
Sent when an error has been found during the validation process.
qgsgeometryvalidator.h
qgsgeos.h