QGIS API Documentation 4.1.0-Master (60fea48833c)
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
20#include "qgsapplication.h"
21
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27 const QgsGeometryCheck *check, const QString &layerId, QgsFeatureId featureId, const QgsGeometry &geometry, const QgsPointXY &errorLocation, QgsVertexId vidx, const QVariant &value, ValueType valueType
28)
29 : mCheck( check )
30 , mLayerId( layerId )
33 , mErrorLocation( errorLocation )
34 , mVidx( vidx )
35 , mValue( value )
38{}
39
41 const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, QgsVertexId vidx, const QVariant &value, ValueType valueType
42)
43 : mCheck( check )
44 , mLayerId( layerFeature.layerId() )
45 , mFeatureId( layerFeature.feature().id() )
46 , mErrorLocation( errorLocation )
47 , mVidx( vidx )
48 , mValue( value )
51{
52 if ( vidx.part != -1 )
53 {
54 const QgsGeometry geom = layerFeature.geometry();
55 mGeometry = QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom.constGet(), vidx.part )->clone() );
56 }
57 else
58 {
59 mGeometry = layerFeature.geometry();
60 }
61 if ( !layerFeature.useMapCrs() )
62 {
63 const QgsCoordinateTransform ct( layerFeature.layerCrs(), check->context()->mapCrs, check->context()->transformContext );
64 try
65 {
66 mGeometry.transform( ct );
67 mErrorLocation = ct.transform( mErrorLocation );
68 }
69 catch ( const QgsCsException & )
70 {
71 QgsDebugError( u"Can not show error in current map coordinate reference system"_s );
72 }
73 }
74}
75
80
85
87{
88 return mGeometry.boundingBox();
89}
90
92{
94 const QList<QgsGeometryCheckResolutionMethod> methods = mCheck->availableResolutionMethods();
95 for ( const QgsGeometryCheckResolutionMethod &fix : methods )
96 {
97 if ( fix.id() == method )
98 mResolutionMessage = fix.name();
99 }
100}
101
102void QgsGeometryCheckError::setFixFailed( const QString &reason )
103{
105 mResolutionMessage = reason;
106}
107
109{
110 return other->check() == check() && other->layerId() == layerId() && other->featureId() == featureId() && other->vidx() == vidx();
111}
112
114{
115 return false;
116}
117
119{
120 if ( status() == StatusObsolete )
121 {
122 return false;
123 }
124
125 for ( const QgsGeometryCheck::Change &change : changes.value( layerId() ).value( featureId() ) )
126 {
127 if ( change.what == QgsGeometryCheck::ChangeFeature )
128 {
129 if ( change.type == QgsGeometryCheck::ChangeRemoved )
130 {
131 return false;
132 }
133 else if ( change.type == QgsGeometryCheck::ChangeChanged )
134 {
135 // If the check is checking the feature at geometry nodes level, the
136 // error almost certainly invalid after a geometry change. In the other
137 // cases, it might likely still be valid.
138 return mCheck->checkType() != QgsGeometryCheck::FeatureNodeCheck;
139 }
140 }
141 else if ( change.what == QgsGeometryCheck::ChangePart )
142 {
143 if ( mVidx.part == change.vidx.part )
144 {
145 return false;
146 }
147 else if ( mVidx.part > change.vidx.part )
148 {
149 mVidx.part += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
150 }
151 }
152 else if ( change.what == QgsGeometryCheck::ChangeRing )
153 {
154 if ( mVidx.partEqual( change.vidx ) )
155 {
156 if ( mVidx.ring == change.vidx.ring )
157 {
158 return false;
159 }
160 else if ( mVidx.ring > change.vidx.ring )
161 {
162 mVidx.ring += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
163 }
164 }
165 }
166 else if ( change.what == QgsGeometryCheck::ChangeNode )
167 {
168 if ( mVidx.ringEqual( change.vidx ) )
169 {
170 if ( mVidx.vertex == change.vidx.vertex )
171 {
172 return false;
173 }
174 else if ( mVidx.vertex > change.vidx.vertex )
175 {
176 mVidx.vertex += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
177 }
178 }
179 }
180 }
181 return true;
182}
183
184QMap<QString, QgsFeatureIds> QgsGeometryCheckError::involvedFeatures() const
185{
186 return QMap<QString, QSet<QgsFeatureId>>();
187}
188
190{
192 return QgsApplication::getThemeIcon( u"/algorithms/mAlgorithmCheckGeometry.svg"_s );
193 else
194 return QgsApplication::getThemeIcon( u"/algorithms/mAlgorithmLineIntersections.svg"_s );
195}
196
198{
199 Q_ASSERT( mCheck == other->mCheck );
200 Q_ASSERT( mLayerId == other->mLayerId );
201 Q_ASSERT( mFeatureId == other->mFeatureId );
203 mVidx = other->mVidx;
204 mValue = other->mValue;
205 mGeometry = other->mGeometry;
206}
207
208QgsGeometryCheck::LayerFeatureIds::LayerFeatureIds( const QMap<QString, QgsFeatureIds> &idsIn )
209 : ids( idsIn )
210{}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Custom exception class for Coordinate Reference System related exceptions.
ValueType
Describes the type of an error value.
virtual QMap< QString, QgsFeatureIds > involvedFeatures() const
Returns a list of involved features.
@ StatusPending
The error is detected and pending to be handled.
@ 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.
ValueType valueType() const
The type of the value.
QgsGeometry geometry() const
The geometry of the error in map units.
QVariant value() const
An additional value for the error.
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.
Implements a resolution for problems detected in geometry checks.
Base class for geometry checks.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
@ 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.
A layer feature combination to uniquely identify and access a feature in a set of layers.
bool useMapCrs() const
Returns if the geometry is reprojected to the map CRS or not.
A geometry is the spatial representation of a feature.
Represents a 2D point.
Definition qgspointxy.h:62
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:59
Descripts a change to fix a geometry.
QMap< QString, QgsFeatureIds > ids
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:34