QGIS API Documentation  3.6.0-Noosa (5873452)
qgsgeometryoverlapcheck.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometryoverlapcheck.h
3  ---------------------
4  begin : September 2015
5  copyright : (C) 2014 by Sandro Mani / Sourcepole AG
6  email : smani at sourcepole dot ch
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 #define SIP_NO_FILE
17 
18 #ifndef QGS_GEOMETRY_OVERLAP_CHECK_H
19 #define QGS_GEOMETRY_OVERLAP_CHECK_H
20 
21 #include "qgsgeometrycheck.h"
22 #include "qgsgeometrycheckerror.h"
23 
31 {
32  public:
33 
35  {
36  public:
38  : mLayerId( vl->id() )
39  , mLayerName( vl->name() )
40  , mFeatureId( fid )
41  {}
42 
43  QString layerId() const {return mLayerId;}
44  QString layerName() const {return mLayerName;}
45  QgsFeatureId featureId() const {return mFeatureId;}
46  bool operator==( const OverlappedFeature &other ) const {return mLayerId == other.layerId() && mFeatureId == other.featureId();}
47 
48  private:
49  QString mLayerId;
50  QString mLayerName;
51  QgsFeatureId mFeatureId;
52  };
53 
61  const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
62  const QgsGeometry &geometry,
63  const QgsPointXY &errorLocation,
64  const QVariant &value,
65  const QgsGeometryCheckerUtils::LayerFeature &overlappedFeature );
66 
70  const OverlappedFeature &overlappedFeature() const { return mOverlappedFeature; }
71 
72  bool isEqual( QgsGeometryCheckError *other ) const override
73  {
74  QgsGeometryOverlapCheckError *err = dynamic_cast<QgsGeometryOverlapCheckError *>( other );
75  return err &&
76  other->layerId() == layerId() &&
77  other->featureId() == featureId() &&
78  err->overlappedFeature() == overlappedFeature() &&
79  QgsGeometryCheckerUtils::pointsFuzzyEqual( location(), other->location(), mCheck->context()->reducedTolerance ) &&
80  std::fabs( value().toDouble() - other->value().toDouble() ) < mCheck->context()->reducedTolerance;
81  }
82 
83  bool closeMatch( QgsGeometryCheckError *other ) const override
84  {
85  QgsGeometryOverlapCheckError *err = dynamic_cast<QgsGeometryOverlapCheckError *>( other );
86  return err && other->layerId() == layerId() && other->featureId() == featureId() && err->overlappedFeature() == overlappedFeature();
87  }
88 
89  bool handleChanges( const QgsGeometryCheck::Changes &changes ) override
90  {
91  if ( !QgsGeometryCheckError::handleChanges( changes ) )
92  {
93  return false;
94  }
95  if ( changes.value( mOverlappedFeature.layerId() ).keys().contains( mOverlappedFeature.featureId() ) )
96  {
97  return false;
98  }
99  return true;
100  }
101 
102  QString description() const override;
103 
104  private:
105  OverlappedFeature mOverlappedFeature;
106 };
107 
114 class ANALYSIS_EXPORT QgsGeometryOverlapCheck : public QgsGeometryCheck
115 {
116  public:
117 
122  {
124  NoChange
125  };
126 
135  QgsGeometryOverlapCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
136  QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return factoryCompatibleGeometryTypes(); }
137  void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
138  void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
139  QStringList resolutionMethods() const override;
140 
141  QString description() const override;
142  QString id() const override;
143  QgsGeometryCheck::Flags flags() const override;
144  QgsGeometryCheck::CheckType checkType() const override { return factoryCheckType(); }
145 
147  static QString factoryDescription() SIP_SKIP;
148  static QString factoryId() SIP_SKIP;
149  static QgsGeometryCheck::Flags factoryFlags() SIP_SKIP;
150  static QList<QgsWkbTypes::GeometryType> factoryCompatibleGeometryTypes() SIP_SKIP;
151  static bool factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP;
152  static QgsGeometryCheck::CheckType factoryCheckType() SIP_SKIP;
154 
155  private:
156  const double mOverlapThresholdMapUnits;
157 
158 };
159 
160 #endif // QGS_GEOMETRY_OVERLAP_CHECK_H
Subtract the overlap region from the polygon.
static bool pointsFuzzyEqual(const QgsPointXY &p1, const QgsPointXY &p2, double tol)
Determine whether two points are equal up to the specified tolerance.
bool closeMatch(QgsGeometryCheckError *other) const override
Check if this error is almost equal to other.
Checks if geometries overlap.
A class to represent a 2D point.
Definition: qgspointxy.h:43
const QgsPointXY & location() const
The location of the error in map units.
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
CheckType
The type of a check.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
Base configuration for geometry checks.
An error of a QgsGeometryOverlapCheck.
#define SIP_SKIP
Definition: qgis_sip.h:119
const OverlappedFeature & overlappedFeature() const
Returns the overlapped feature.
A layer feature combination to uniquely identify and access a feature in a set of layers...
This class implements a geometry check.
bool isEqual(QgsGeometryCheckError *other) const override
Check if this error is equal to other.
const QString & layerId() const
The id of the layer on which this error has been detected.
A list of layers and feature ids for each of these layers.
QgsGeometryCheck::CheckType checkType() const override
Returns the check type.
bool operator==(const OverlappedFeature &other) const
ResolutionMethod
Available resolution methods.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
virtual bool handleChanges(const QgsGeometryCheck::Changes &changes)
Apply a list of changes.
bool handleChanges(const QgsGeometryCheck::Changes &changes) override
Apply a list of changes.
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
This represents an error reported by a geometry check.
QVariant value() const
An additional value for the error.
OverlappedFeature(QgsVectorLayer *vl, QgsFeatureId fid)
Represents a vector layer which manages a vector based data sets.