QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  Q_DECLARE_TR_FUNCTIONS( QgsGeometryDuplicateCheck )
62  public:
63  explicit QgsGeometryDuplicateCheck( QgsGeometryCheckContext *context, const QVariantMap &configuration )
64  : QgsGeometryCheck( context, configuration ) {}
65  void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
66  void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
67 
68  QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return factoryCompatibleGeometryTypes(); }
69  Q_DECL_DEPRECATED QStringList resolutionMethods() const override;
70  QString description() const override { return factoryDescription(); }
71  QString id() const override { return factoryId(); }
72  QgsGeometryCheck::CheckType checkType() const override { return factoryCheckType(); }
73 
75  static bool factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP { return factoryCompatibleGeometryTypes().contains( layer->geometryType() ); }
76  static QString factoryDescription() { return tr( "Duplicate" ); }
77  static QString factoryId();
78  static QgsGeometryCheck::CheckType factoryCheckType();
79 
80  enum ResolutionMethod { NoChange, RemoveDuplicates };
81 };
82 
83 #endif // QGS_GEOMETRY_DUPLICATE_CHECK_H
QgsGeometryDuplicateCheckError
Definition: qgsgeometryduplicatecheck.h:29
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:72
QgsGeometryDuplicateCheckError::duplicates
QMap< QString, QList< QgsFeatureId > > duplicates() const
Definition: qgsgeometryduplicatecheck.h:39
QgsGeometryDuplicateCheck::factoryDescription
static QString factoryDescription()
Definition: qgsgeometryduplicatecheck.h:76
QgsGeometryDuplicateCheck::compatibleGeometryTypes
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
Definition: qgsgeometryduplicatecheck.h:68
QgsGeometryDuplicateCheck::factoryIsCompatible
static bool factoryIsCompatible(QgsVectorLayer *layer)
Definition: qgsgeometryduplicatecheck.h:75
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:144
QgsGeometryDuplicateCheck::description
QString description() const override
Returns a human readable description for this check.
Definition: qgsgeometryduplicatecheck.h:70
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
This class implements a geometry check.
Definition: qgsgeometrycheck.h:92
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:74
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgsgeometrycheckcontext.h
qgsgeometrycheck.h
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsGeometryDuplicateCheck::id
QString id() const override
Returns an id for this check.
Definition: qgsgeometryduplicatecheck.h:71
QgsGeometryDuplicateCheck
Definition: qgsgeometryduplicatecheck.h:60
QgsGeometryCheckContext
Base configuration for geometry checks.
Definition: qgsgeometrycheckcontext.h:32
QgsGeometryCheckerUtils::LayerFeature
A layer feature combination to uniquely identify and access a feature in a set of layers.
Definition: qgsgeometrycheckerutils.h:52
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:80
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:142
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
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:1059
QgsGeometryCheckError::layerId
const QString & layerId() const
The id of the layer on which this error has been detected.
Definition: qgsgeometrycheckerror.h:85
QgsGeometryCheckError
This represents an error reported by a geometry check.
Definition: qgsgeometrycheckerror.h:36
QgsGeometryDuplicateCheck::QgsGeometryDuplicateCheck
QgsGeometryDuplicateCheck(QgsGeometryCheckContext *context, const QVariantMap &configuration)
Definition: qgsgeometryduplicatecheck.h:63