QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgssinglegeometrycheck.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssinglegeometrycheck.cpp
3  --------------------------------------
4 Date : 6.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 
16 #include "qgssinglegeometrycheck.h"
18 #include "qgspoint.h"
19 
20 
21 
22 void QgsSingleGeometryCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools,
23  QList<QgsGeometryCheckError *> &errors,
24  QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
25 {
26  Q_UNUSED( messages )
27  const QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
28  const QgsGeometryCheckerUtils::LayerFeatures layerFeatures( featurePools, featureIds, compatibleGeometryTypes(), feedback, mContext );
29  for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
30  {
31  const auto singleErrors = processGeometry( layerFeature.geometry() );
32  for ( const auto error : singleErrors )
33  errors.append( convertToGeometryCheckError( error, layerFeature ) );
34  }
35 }
36 
37 QgsGeometryCheckErrorSingle *QgsSingleGeometryCheck::convertToGeometryCheckError( QgsSingleGeometryCheckError *singleGeometryCheckError, const QgsGeometryCheckerUtils::LayerFeature &layerFeature ) const
38 {
39  return new QgsGeometryCheckErrorSingle( singleGeometryCheckError, layerFeature );
40 }
41 
43 {
44  Q_ASSERT( mCheck == other->mCheck );
46  mVertexId = other->mVertexId;
47  mGeometry = other->mGeometry;
48 }
49 
51 {
52  return mGeometry.equals( other->mGeometry )
53  && mCheck == other->mCheck
55  && mVertexId == other->mVertexId;
56 }
57 
58 bool QgsSingleGeometryCheckError::handleChanges( const QList<QgsGeometryCheck::Change> &changes )
59 {
60  Q_UNUSED( changes )
61  return true;
62 }
63 
65 {
66  return mCheck->description();
67 }
68 
70 {
71  return mCheck;
72 }
73 
75 {
76  return mErrorLocation;
77 }
78 
80 {
81  return mVertexId;
82 }
83 
85  : QgsGeometryCheckError( error->check(), layerFeature, QgsPointXY( error->errorLocation().constGet()->centroid() ), error->vertexId() ) // TODO: should send geometry to QgsGeometryCheckError
86  , mError( error )
87 {
88 
89 }
90 
92 {
93  return mError;
94 }
95 
97 {
98  if ( !QgsGeometryCheckError::handleChanges( changes ) )
99  return false;
100 
101  return mError->handleChanges( changes.value( layerId() ).value( featureId() ) );
102 }
QgsGeometryCheckError::value
QVariant value() const
An additional value for the error.
Definition: qgsgeometrycheckerror.h:128
QgsGeometryCheck::compatibleGeometryTypes
virtual QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const =0
A list of geometry types for which this check can be performed.
QgsSingleGeometryCheckError::errorLocation
QgsGeometry errorLocation() const
The exact location of the error.
Definition: qgssinglegeometrycheck.cpp:74
QgsMeshUtils::centroid
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
Definition: qgstriangularmesh.cpp:955
QgsGeometryCheckErrorSingle::QgsGeometryCheckErrorSingle
QgsGeometryCheckErrorSingle(QgsSingleGeometryCheckError *singleError, const QgsGeometryCheckerUtils::LayerFeature &layerFeature)
Creates a new error for a QgsSingleGeometryCheck.
Definition: qgssinglegeometrycheck.cpp:84
QgsGeometryCheckError::featureId
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
Definition: qgsgeometrycheckerror.h:90
QgsGeometryCheck::Changes
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
Definition: qgsgeometrycheck.h:220
QgsGeometryCheck::allLayerFeatureIds
QMap< QString, QgsFeatureIds > allLayerFeatureIds(const QMap< QString, QgsFeaturePool * > &featurePools) const
Returns all layers and feature ids.
Definition: qgsgeometrycheck.cpp:82
QgsGeometryCheck::description
virtual QString description() const =0
Returns a human readable description for this check.
QgsGeometryCheck::LayerFeatureIds::isEmpty
bool isEmpty() const
Definition: qgsgeometrycheck.h:117
QgsSingleGeometryCheckError::mCheck
const QgsSingleGeometryCheck * mCheck
Definition: qgssinglegeometrycheck.h:100
QgsSingleGeometryCheckError::vertexId
QgsVertexId vertexId() const
The vertex id of the error.
Definition: qgssinglegeometrycheck.cpp:79
QgsSingleGeometryCheckError::update
virtual void update(const QgsSingleGeometryCheckError *other)
Update this error with the information from other.
Definition: qgssinglegeometrycheck.cpp:42
qgspoint.h
QgsSingleGeometryCheckError
An error from a QgsSingleGeometryCheck.
Definition: qgssinglegeometrycheck.h:39
QgsSingleGeometryCheckError::mErrorLocation
QgsGeometry mErrorLocation
Definition: qgssinglegeometrycheck.h:102
QgsGeometryCheck::LayerFeatureIds::toMap
QMap< QString, QgsFeatureIds > toMap() const
Definition: qgsgeometrycheck.h:112
QgsSingleGeometryCheckError::mVertexId
QgsVertexId mVertexId
Definition: qgssinglegeometrycheck.h:103
QgsSingleGeometryCheck::processGeometry
virtual QList< QgsSingleGeometryCheckError * > processGeometry(const QgsGeometry &geometry) const =0
Check the geometry for errors.
QgsSingleGeometryCheckError::description
virtual QString description() const
A human readable description of this error.
Definition: qgssinglegeometrycheck.cpp:64
QgsSingleGeometryCheck
Base class for geometry checks for a single geometry without any context of the layer or other layers...
Definition: qgssinglegeometrycheck.h:149
QgsGeometryCheckErrorSingle::handleChanges
bool handleChanges(const QgsGeometryCheck::Changes &changes) override
Apply a list of changes.
Definition: qgssinglegeometrycheck.cpp:96
qgsgeometrycheckcontext.h
QgsSingleGeometryCheck::collectErrors
void collectErrors(const QMap< QString, QgsFeaturePool * > &featurePools, QList< QgsGeometryCheckError * > &errors, QStringList &messages, QgsFeedback *feedback=nullptr, const QgsGeometryCheck::LayerFeatureIds &ids=QgsGeometryCheck::LayerFeatureIds()) const FINAL
The main worker method.
Definition: qgssinglegeometrycheck.cpp:22
QgsGeometryCheckError::handleChanges
virtual bool handleChanges(const QgsGeometryCheck::Changes &changes)
Apply a list of changes.
Definition: qgsgeometrycheckerror.cpp:128
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsGeometry::equals
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
Definition: qgsgeometry.cpp:1340
QgsGeometryCheckerUtils::LayerFeature
A layer feature combination to uniquely identify and access a feature in a set of layers.
Definition: qgsgeometrycheckerutils.h:51
QgsGeometryCheck::LayerFeatureIds
A list of layers and feature ids for each of these layers.
Definition: qgsgeometrycheck.h:104
QgsSingleGeometryCheckError::check
const QgsSingleGeometryCheck * check() const
The check that created this error.
Definition: qgssinglegeometrycheck.cpp:69
QgsGeometryCheckErrorSingle
Wraps a QgsSingleGeometryError into a standard QgsGeometryCheckError. The single error can be obtaine...
Definition: qgssinglegeometrycheck.h:115
QgsGeometryCheck::mContext
const QgsGeometryCheckContext * mContext
Definition: qgsgeometrycheck.h:365
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsSingleGeometryCheckError::isEqual
virtual bool isEqual(const QgsSingleGeometryCheckError *other) const
Check if this error is equal to other.
Definition: qgssinglegeometrycheck.cpp:50
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsGeometryCheckerUtils::LayerFeatures
Contains a set of layers and feature ids in those layers to pass to a geometry check.
Definition: qgsgeometrycheckerutils.h:112
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsvertexid.h:30
QgsGeometryCheckError::layerId
const QString & layerId() const
The id of the layer on which this error has been detected.
Definition: qgsgeometrycheckerror.h:85
qgssinglegeometrycheck.h
QgsSingleGeometryCheckError::mGeometry
QgsGeometry mGeometry
Definition: qgssinglegeometrycheck.h:101
QgsGeometryCheckError
This represents an error reported by a geometry check.
Definition: qgsgeometrycheckerror.h:35
QgsGeometryCheckErrorSingle::singleError
QgsSingleGeometryCheckError * singleError() const
The underlying single error.
Definition: qgssinglegeometrycheck.cpp:91
QgsSingleGeometryCheckError::handleChanges
virtual bool handleChanges(const QList< QgsGeometryCheck::Change > &changes)
Apply a list of changes.
Definition: qgssinglegeometrycheck.cpp:58