QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsgeometryduplicatecheck.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometryduplicatecheck.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_DUPLICATE_CHECK_H
19 #define QGS_GEOMETRY_DUPLICATE_CHECK_H
20 
22 #include "qgsgeometrycheck.h"
23 #include "qgsgeometrycheckerror.h"
24 
29 {
30  public:
32  const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
33  const QgsPointXY &errorLocation,
34  const QMap<QString, QgsFeaturePool *> &featurePools,
35  const QMap<QString, QList<QgsFeatureId>> &duplicates )
36  : QgsGeometryCheckError( check, layerFeature, errorLocation, QgsVertexId(), duplicatesString( featurePools, duplicates ) )
37  , mDuplicates( duplicates )
38  { }
39  QMap<QString, QList<QgsFeatureId>> duplicates() const { return mDuplicates; }
40 
41  bool isEqual( QgsGeometryCheckError *other ) const override
42  {
43  return other->check() == check() &&
44  other->layerId() == layerId() &&
45  other->featureId() == featureId() &&
46  // static_cast: since other->checker() == checker is only true if the types are actually the same
47  static_cast<QgsGeometryDuplicateCheckError *>( other )->duplicates() == duplicates();
48  }
49 
50  private:
51  QMap<QString, QList<QgsFeatureId>> mDuplicates;
52 
53  static QString duplicatesString( const QMap<QString, QgsFeaturePool *> &featurePools, const QMap<QString, QList<QgsFeatureId>> &duplicates );
54 };
55 
59 class ANALYSIS_EXPORT QgsGeometryDuplicateCheck : public QgsGeometryCheck
60 {
61  public:
62  explicit QgsGeometryDuplicateCheck( QgsGeometryCheckContext *context, const QVariantMap &configuration )
63  : QgsGeometryCheck( context, configuration ) {}
64  void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
65  void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
66 
67  QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return factoryCompatibleGeometryTypes(); }
68  Q_DECL_DEPRECATED QStringList resolutionMethods() const override;
69  QString description() const override { return factoryDescription(); }
70  QString id() const override { return factoryId(); }
71  QgsGeometryCheck::CheckType checkType() const override { return factoryCheckType(); }
72 
74  static bool factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP { return factoryCompatibleGeometryTypes().contains( layer->geometryType() ); }
75  static QString factoryDescription() { return tr( "Duplicate" ); }
76  static QString factoryId();
77  static QgsGeometryCheck::CheckType factoryCheckType();
78 
79  enum ResolutionMethod { NoChange, RemoveDuplicates };
80 };
81 
82 #endif // QGS_GEOMETRY_DUPLICATE_CHECK_H
QgsGeometryDuplicateCheckError
Definition: qgsgeometryduplicatecheck.h:28
QgsGeometryCheckError::check
const QgsGeometryCheck * check() const
The geometry check that created this error.
Definition: qgsgeometrycheckerror.h:80
QgsGeometryCheckError::featureId
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
Definition: qgsgeometrycheckerror.h:90
QgsGeometryDuplicateCheck::checkType
QgsGeometryCheck::CheckType checkType() const override
Returns the check type.
Definition: qgsgeometryduplicatecheck.h:71
QgsGeometryDuplicateCheckError::duplicates
QMap< QString, QList< QgsFeatureId > > duplicates() const
Definition: qgsgeometryduplicatecheck.h:39
QgsGeometryDuplicateCheck::factoryDescription
static QString factoryDescription()
Definition: qgsgeometryduplicatecheck.h:75
QgsGeometryDuplicateCheck::compatibleGeometryTypes
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
Definition: qgsgeometryduplicatecheck.h:67
QgsGeometryDuplicateCheck::factoryIsCompatible
static bool factoryIsCompatible(QgsVectorLayer *layer)
Definition: qgsgeometryduplicatecheck.h:74
QgsGeometryCheck::resolutionMethods
virtual Q_DECL_DEPRECATED QStringList resolutionMethods() const
Returns a list of descriptions for available resolutions for errors.
Definition: qgsgeometrycheck.cpp:77
qgsgeometrycheckerror.h
QgsGeometryCheck::collectErrors
virtual void collectErrors(const QMap< QString, QgsFeaturePool * > &featurePools, QList< QgsGeometryCheckError * > &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids=QgsGeometryCheck::LayerFeatureIds()) const =0
The main worker method.
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:143
QgsGeometryDuplicateCheck::description
QString description() const override
Returns a human readable description for this check.
Definition: qgsgeometryduplicatecheck.h:69
QgsGeometryDuplicateCheckError::QgsGeometryDuplicateCheckError
QgsGeometryDuplicateCheckError(const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, const QMap< QString, QgsFeaturePool * > &featurePools, const QMap< QString, QList< QgsFeatureId >> &duplicates)
Definition: qgsgeometryduplicatecheck.h:31
QgsGeometryCheck
Definition: qgsgeometrycheck.h:91
QgsGeometryCheck::fixError
virtual void fixError(const QMap< QString, QgsFeaturePool * > &featurePools, QgsGeometryCheckError *error, int method, const QMap< QString, int > &mergeAttributeIndices, Changes &changes) const
Fixes the error error with the specified method.
Definition: qgsgeometrycheck.cpp:50
QgsGeometryDuplicateCheck::factoryCompatibleGeometryTypes
static QList< QgsWkbTypes::GeometryType > factoryCompatibleGeometryTypes()
Definition: qgsgeometryduplicatecheck.h:73
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgsgeometrycheckcontext.h
qgsgeometrycheck.h
QgsFeedback
Definition: qgsfeedback.h:43
QgsGeometryDuplicateCheck::id
QString id() const override
Returns an id for this check.
Definition: qgsgeometryduplicatecheck.h:70
QgsGeometryDuplicateCheck
Definition: qgsgeometryduplicatecheck.h:59
QgsGeometryCheckContext
Definition: qgsgeometrycheckcontext.h:31
QgsGeometryCheckerUtils::LayerFeature
Definition: qgsgeometrycheckerutils.h:51
QgsGeometryDuplicateCheckError::isEqual
bool isEqual(QgsGeometryCheckError *other) const override
Check if this error is equal to other.
Definition: qgsgeometryduplicatecheck.h:41
QgsGeometryDuplicateCheck::ResolutionMethod
ResolutionMethod
Definition: qgsgeometryduplicatecheck.h:79
QgsPointXY
Definition: qgspointxy.h:43
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:142
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:141
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsGeometryCheck::CheckType
CheckType
The type of a check.
Definition: qgsgeometrycheck.h:155
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsabstractgeometry.h:1033
QgsGeometryCheckError::layerId
const QString & layerId() const
The id of the layer on which this error has been detected.
Definition: qgsgeometrycheckerror.h:85
QgsGeometryCheckError
Definition: qgsgeometrycheckerror.h:35
QgsGeometryDuplicateCheck::QgsGeometryDuplicateCheck
QgsGeometryDuplicateCheck(QgsGeometryCheckContext *context, const QVariantMap &configuration)
Definition: qgsgeometryduplicatecheck.h:62