QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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
6  email : [email protected]
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 
18 #include "qgsgeometrycheckerror.h"
19 #include "qgsapplication.h"
20 
22  const QString &layerId,
23  QgsFeatureId featureId,
24  const QgsGeometry &geometry,
25  const QgsPointXY &errorLocation,
26  QgsVertexId vidx,
27  const QVariant &value, ValueType valueType )
28  : mCheck( check )
29  , mLayerId( layerId )
30  , mFeatureId( featureId )
31  , mGeometry( geometry )
32  , mErrorLocation( errorLocation )
33  , mVidx( vidx )
34  , mValue( value )
35  , mValueType( valueType )
36  , mStatus( StatusPending )
37 {
38 }
39 
41  const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
42  const QgsPointXY &errorLocation,
44  const QVariant &value,
46  : mCheck( check )
47  , mLayerId( layerFeature.layerId() )
48  , mFeatureId( layerFeature.feature().id() )
49  , mErrorLocation( errorLocation )
50  , mVidx( vidx )
51  , mValue( value )
52  , mValueType( valueType )
54 {
55  if ( vidx.part != -1 )
56  {
57  const QgsGeometry geom = layerFeature.geometry();
59  }
60  else
61  {
62  mGeometry = layerFeature.geometry();
63  }
64  if ( !layerFeature.useMapCrs() )
65  {
66  QgsVectorLayer *vl = layerFeature.layer().data();
67  if ( vl )
68  {
69  QgsCoordinateTransform ct( vl->crs(), check->context()->mapCrs, check->context()->transformContext );
70  try
71  {
72  mGeometry.transform( ct );
73  mErrorLocation = ct.transform( mErrorLocation );
74  }
75  catch ( const QgsCsException & )
76  {
77  QgsDebugMsg( QStringLiteral( "Can not show error in current map coordinate reference system" ) );
78  }
79  }
80  }
81 }
82 
84 {
85  return mGeometry;
86 }
87 
89 {
90  return mGeometry.boundingBox();
91 }
92 
94 {
96  const QStringList methods = mCheck->resolutionMethods();
97  mResolutionMessage = methods[method];
98 }
99 
100 void QgsGeometryCheckError::setFixFailed( const QString &reason )
101 {
103  mResolutionMessage = reason;
104 }
105 
107 {
108  return other->check() == check() &&
109  other->layerId() == layerId() &&
110  other->featureId() == featureId() &&
111  other->vidx() == vidx();
112 }
113 
115 {
116  return false;
117 }
118 
120 {
121  if ( status() == StatusObsolete )
122  {
123  return false;
124  }
125 
126  for ( const QgsGeometryCheck::Change &change : changes.value( layerId() ).value( featureId() ) )
127  {
128  if ( change.what == QgsGeometryCheck::ChangeFeature )
129  {
130  if ( change.type == QgsGeometryCheck::ChangeRemoved )
131  {
132  return false;
133  }
134  else if ( change.type == QgsGeometryCheck::ChangeChanged )
135  {
136  // If the check is checking the feature at geometry nodes level, the
137  // error almost certainly invalid after a geometry change. In the other
138  // cases, it might likely still be valid.
140  }
141  }
142  else if ( change.what == QgsGeometryCheck::ChangePart )
143  {
144  if ( mVidx.part == change.vidx.part )
145  {
146  return false;
147  }
148  else if ( mVidx.part > change.vidx.part )
149  {
150  mVidx.part += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
151  }
152  }
153  else if ( change.what == QgsGeometryCheck::ChangeRing )
154  {
155  if ( mVidx.partEqual( change.vidx ) )
156  {
157  if ( mVidx.ring == change.vidx.ring )
158  {
159  return false;
160  }
161  else if ( mVidx.ring > change.vidx.ring )
162  {
163  mVidx.ring += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
164  }
165  }
166  }
167  else if ( change.what == QgsGeometryCheck::ChangeNode )
168  {
169  if ( mVidx.ringEqual( change.vidx ) )
170  {
171  if ( mVidx.vertex == change.vidx.vertex )
172  {
173  return false;
174  }
175  else if ( mVidx.vertex > change.vidx.vertex )
176  {
177  mVidx.vertex += change.type == QgsGeometryCheck::ChangeAdded ? 1 : -1;
178  }
179  }
180  }
181  }
182  return true;
183 }
184 
185 QMap<QString, QgsFeatureIds> QgsGeometryCheckError::involvedFeatures() const
186 {
187  return QMap<QString, QSet<QgsFeatureId> >();
188 }
189 
191 {
193  return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCheckGeometry.svg" ) );
194  else
195  return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmLineIntersections.svg" ) );
196 }
197 
199 {
200  Q_ASSERT( mCheck == other->mCheck );
201  Q_ASSERT( mLayerId == other->mLayerId );
202  Q_ASSERT( mFeatureId == other->mFeatureId );
204  mVidx = other->mVidx;
205  mValue = other->mValue;
206  mGeometry = other->mGeometry;
207 }
208 
209 QgsGeometryCheck::LayerFeatureIds::LayerFeatureIds( const QMap<QString, QgsFeatureIds> &ids )
210  : ids( ids )
211 {
212 }
The error is obsolete because of other modifications.
This change happens on part level.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
The error is detected and pending to be handled.
virtual void update(const QgsGeometryCheckError *other)
Update this error with the information from other.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
Something has been added.
const QgsCoordinateReferenceSystem mapCrs
The coordinate system in which calculations should be done.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
A class to represent a 2D point.
Definition: qgspointxy.h:43
virtual bool closeMatch(QgsGeometryCheckError *) const
Check if this error is almost equal to other.
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
ValueType
Describes the type of an error value.
void setFixFailed(const QString &reason)
Set the error status to failed and specify the reason for failure.
Something has been removed.
const QgsGeometryCheck * check() const
The geometry check that created this error.
This change happens on ring level.
QPointer< QgsVectorLayer > layer() const
The layer.
Utility class for identifying a unique vertex within a geometry.
virtual CheckType checkType() const =0
Returns the check type.
A layer feature combination to uniquely identify and access a feature in a set of layers...
const QgsGeometryCheck * mCheck
This class implements a geometry check.
const QString & layerId() const
The id of the layer on which this error has been detected.
virtual QIcon icon() const
Returns an icon that should be shown for this kind of error.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsGeometry geometry() const
The geometry of the error in map units.
Status status() const
The status of the error.
virtual QMap< QString, QgsFeatureIds > involvedFeatures() const
Returns a list of involved features.
bool partEqual(QgsVertexId o) const
bool ringEqual(QgsVertexId o) const
bool useMapCrs() const
Returns if the geometry is reprojected to the map CRS or not.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
virtual QgsRectangle affectedAreaBBox() const
The bounding box of the affected area of the error.
Descripts a change to fix a geometry.
QgsGeometry geometry() const
Returns the geometry of this feature.
void setFixed(int method)
Set the status to fixed and specify the method that has been used to fix the error.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
virtual bool handleChanges(const QgsGeometryCheck::Changes &changes)
Apply a list of changes.
A fix has been tried on the error but failed.
Class for doing transforms between two map coordinate systems.
virtual QStringList resolutionMethods() const =0
Returns a list of descriptions for available resolutions for errors.
const QgsCoordinateTransformContext transformContext
The coordinate transform context with which transformations will be done.
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
const QgsGeometryCheckContext * context() const
Returns the context.
This represents an error reported by a geometry check.
This change happens on node level.
QVariant value() const
An additional value for the error.
ValueType valueType() const
The type of the value.
Represents a vector layer which manages a vector based data sets.
Something has been updated.
const QgsVertexId & vidx() const
The id of the affected vertex.
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...
This change happens on feature level.
virtual bool isEqual(QgsGeometryCheckError *other) const
Check if this error is equal to other.
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:85
The check controls individual nodes.