QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsgeometrycheckerror.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometrycheckerror.cpp
3 --------
4 begin : September 2018
5 copyright : (C) 2018 by Denis Rouzaud
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "qgsapplication.h"
20
21QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check, const QString &layerId, QgsFeatureId featureId, const QgsGeometry &geometry, const QgsPointXY &errorLocation, QgsVertexId vidx, const QVariant &value, ValueType valueType )
22 : mCheck( check )
23 , mLayerId( layerId )
24 , mFeatureId( featureId )
25 , mGeometry( geometry )
26 , mErrorLocation( errorLocation )
27 , mVidx( vidx )
28 , mValue( value )
29 , mValueType( valueType )
30 , mStatus( StatusPending )
31{
32}
33
34QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, QgsVertexId vidx, const QVariant &value, ValueType valueType )
35 : mCheck( check )
36 , mLayerId( layerFeature.layerId() )
37 , mFeatureId( layerFeature.feature().id() )
38 , mErrorLocation( errorLocation )
39 , mVidx( vidx )
40 , mValue( value )
41 , mValueType( valueType )
42 , mStatus( StatusPending )
43{
44 if ( vidx.part != -1 )
45 {
46 const QgsGeometry geom = layerFeature.geometry();
48 }
49 else
50 {
51 mGeometry = layerFeature.geometry();
52 }
53 if ( !layerFeature.useMapCrs() )
54 {
56 try
57 {
58 mGeometry.transform( ct );
60 }
61 catch ( const QgsCsException & )
62 {
63 QgsDebugError( QStringLiteral( "Can not show error in current map coordinate reference system" ) );
64 }
65 }
66}
67
72
77
82
84{
86 const QList<QgsGeometryCheckResolutionMethod> methods = mCheck->availableResolutionMethods();
87 for ( const QgsGeometryCheckResolutionMethod &fix : methods )
88 {
89 if ( fix.id() == method )
90 mResolutionMessage = fix.name();
91 }
92}
93
94void QgsGeometryCheckError::setFixFailed( const QString &reason )
95{
97 mResolutionMessage = reason;
98}
99
101{
102 return other->check() == check() && other->layerId() == layerId() && other->featureId() == featureId() && other->vidx() == vidx();
103}
104
106{
107 return false;
108}
109
111{
112 if ( status() == StatusObsolete )
113 {
114 return false;
115 }
116
117 for ( const QgsGeometryCheck::Change &change : changes.value( layerId() ).value( featureId() ) )
118 {
119 if ( change.what == QgsGeometryCheck::ChangeFeature )
120 {
121 if ( change.type == QgsGeometryCheck::ChangeRemoved )
122 {
123 return false;
124 }
125 else if ( change.type == QgsGeometryCheck::ChangeChanged )
126 {
127 // If the check is checking the feature at geometry nodes level, the
128 // error almost certainly invalid after a geometry change. In the other
129 // cases, it might likely still be valid.
131 }
132 }
133 else if ( change.what == QgsGeometryCheck::ChangePart )
134 {
135 if ( mVidx.part == change.vidx.part )
136 {
137 return false;
138 }
139 else if ( mVidx.part > change.vidx.part )
140 {
141 mVidx.part += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
142 }
143 }
144 else if ( change.what == QgsGeometryCheck::ChangeRing )
145 {
146 if ( mVidx.partEqual( change.vidx ) )
147 {
148 if ( mVidx.ring == change.vidx.ring )
149 {
150 return false;
151 }
152 else if ( mVidx.ring > change.vidx.ring )
153 {
154 mVidx.ring += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
155 }
156 }
157 }
158 else if ( change.what == QgsGeometryCheck::ChangeNode )
159 {
160 if ( mVidx.ringEqual( change.vidx ) )
161 {
162 if ( mVidx.vertex == change.vidx.vertex )
163 {
164 return false;
165 }
166 else if ( mVidx.vertex > change.vidx.vertex )
167 {
168 mVidx.vertex += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
169 }
170 }
171 }
172 }
173 return true;
174}
175
176QMap<QString, QgsFeatureIds> QgsGeometryCheckError::involvedFeatures() const
177{
178 return QMap<QString, QSet<QgsFeatureId>>();
179}
180
182{
184 return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCheckGeometry.svg" ) );
185 else
186 return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmLineIntersections.svg" ) );
187}
188
190{
191 Q_ASSERT( mCheck == other->mCheck );
192 Q_ASSERT( mLayerId == other->mLayerId );
193 Q_ASSERT( mFeatureId == other->mFeatureId );
195 mVidx = other->mVidx;
196 mValue = other->mValue;
197 mGeometry = other->mGeometry;
198}
199
200QgsGeometryCheck::LayerFeatureIds::LayerFeatureIds( const QMap<QString, QgsFeatureIds> &idsIn )
201 : ids( idsIn )
202{
203}
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Class for doing transforms between two map coordinate systems.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
const QgsCoordinateTransformContext transformContext
The coordinate transform context with which transformations will be done.
const QgsCoordinateReferenceSystem mapCrs
The coordinate system in which calculations should be done.
This represents an error reported by a geometry check.
ValueType
Describes the type of an error value.
virtual QMap< QString, QgsFeatureIds > involvedFeatures() const
Returns a list of involved features.
@ StatusFixed
The error is fixed.
@ StatusFixFailed
A fix has been tried on the error but failed.
@ StatusObsolete
The error is obsolete because of other modifications.
Status status() const
The status of the error.
const QgsVertexId & vidx() const
The id of the affected vertex.
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
virtual void update(const QgsGeometryCheckError *other)
Update this error with the information from other.
const QgsGeometryCheck * mCheck
QgsGeometryCheckError(const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, QgsVertexId vidx=QgsVertexId(), const QVariant &value=QVariant(), ValueType valueType=ValueOther)
Create a new geometry check error with the parent check and for the layerFeature pair at the errorLoc...
void setFixed(int method)
Set the status to fixed and specify the method that has been used to fix the error.
void setFixFailed(const QString &reason)
Set the error status to failed and specify the reason for failure.
QgsGeometry geometry() const
The geometry of the error in map units.
const QgsGeometryCheck * check() const
The geometry check that created this error.
virtual bool isEqual(QgsGeometryCheckError *other) const
Check if this error is equal to other.
const QString & layerId() const
The id of the layer on which this error has been detected.
virtual bool closeMatch(QgsGeometryCheckError *) const
Check if this error is almost equal to other.
virtual QgsRectangle affectedAreaBBox() const
The bounding box of the affected area of the error.
virtual QIcon icon() const
Returns an icon that should be shown for this kind of error.
virtual bool handleChanges(const QgsGeometryCheck::Changes &changes)
Apply a list of changes.
virtual QgsRectangle contextBoundingBox() const
The context of the error.
This class implements a resolution for problems detected in geometry checks.
This class implements a geometry check.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
virtual QList< QgsGeometryCheckResolutionMethod > availableResolutionMethods() const
Returns a list of available resolution methods.
@ ChangeNode
This change happens on node level.
@ ChangeRing
This change happens on ring level.
@ ChangeFeature
This change happens on feature level.
@ ChangePart
This change happens on part level.
@ FeatureNodeCheck
The check controls individual nodes.
@ ChangeChanged
Something has been updated.
@ ChangeAdded
Something has been added.
@ ChangeRemoved
Something has been removed.
virtual CheckType checkType() const =0
Returns the check type.
const QgsGeometryCheckContext * context() const
Returns the context.
A layer feature combination to uniquely identify and access a feature in a set of layers.
QgsGeometry geometry() const
Returns the geometry of this feature.
bool useMapCrs() const
Returns if the geometry is reprojected to the map CRS or not.
QgsCoordinateReferenceSystem layerCrs() const
The layer CRS.
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
A class to represent a 2D point.
Definition qgspointxy.h:60
A rectangle specified with double values.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
#define QgsDebugError(str)
Definition qgslogger.h:38
Descripts a change to fix a geometry.
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30
int vertex
Vertex number.
Definition qgsvertexid.h:94
int part
Part number.
Definition qgsvertexid.h:88
int ring
Ring number.
Definition qgsvertexid.h:91
bool ringEqual(QgsVertexId o) const
Returns true if this vertex ID belongs to the same ring as another vertex ID (i.e.
Definition qgsvertexid.h:68
bool partEqual(QgsVertexId o) const
Returns true if this vertex ID belongs to the same part as another vertex ID.
Definition qgsvertexid.h:59