Branch data Line data Source code
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 : : 24 : : /** 25 : : * \ingroup analysis 26 : : * \brief An error of a QgsGeometryOverlapCheck. 27 : : * 28 : : * \since QGIS 3.4 29 : : */ 30 : 0 : class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckError 31 : : { 32 : : public: 33 : : 34 : 0 : struct OverlappedFeature 35 : : { 36 : : public: 37 : 7 : OverlappedFeature( QgsVectorLayer *vl, QgsFeatureId fid ) 38 : 7 : : mLayerId( vl->id() ) 39 : 7 : , mLayerName( vl->name() ) 40 : 7 : , mFeatureId( fid ) 41 : 7 : {} 42 : : 43 : 3 : QString layerId() const {return mLayerId;} 44 : 0 : QString layerName() const {return mLayerName;} 45 : 2 : QgsFeatureId featureId() const {return mFeatureId;} 46 : 0 : 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 : : 54 : : /** 55 : : * Creates a new overlap check error for \a check and the \a layerFeature combination. 56 : : * The \a geometry and \a errorLocation ned to be in map coordinates. 57 : : * The \a value is the area of the overlapping area in map units. 58 : : * The \a overlappedFeature provides more details about the overlap. 59 : : */ 60 : : QgsGeometryOverlapCheckError( const QgsGeometryCheck *check, 61 : : const QgsGeometryCheckerUtils::LayerFeature &layerFeature, 62 : : const QgsGeometry &geometry, 63 : : const QgsPointXY &errorLocation, 64 : : const QVariant &value, 65 : : const QgsGeometryCheckerUtils::LayerFeature &overlappedFeature ); 66 : : 67 : : /** 68 : : * Returns the overlapped feature 69 : : */ 70 : 5 : const OverlappedFeature &overlappedFeature() const { return mOverlappedFeature; } 71 : : 72 : : bool isEqual( QgsGeometryCheckError *other ) const override; 73 : : 74 : : bool closeMatch( QgsGeometryCheckError *other ) const override; 75 : : 76 : : bool handleChanges( const QgsGeometryCheck::Changes &changes ) override; 77 : : 78 : : QString description() const override; 79 : : 80 : : QMap<QString, QgsFeatureIds > involvedFeatures() const override; 81 : : QIcon icon() const override; 82 : : 83 : : private: 84 : : OverlappedFeature mOverlappedFeature; 85 : : }; 86 : : 87 : : /** 88 : : * \ingroup analysis 89 : : * \brief Checks if geometries overlap. 90 : : * 91 : : * \since QGIS 3.4 92 : : */ 93 : 3 : class ANALYSIS_EXPORT QgsGeometryOverlapCheck : public QgsGeometryCheck 94 : : { 95 : 6 : Q_DECLARE_TR_FUNCTIONS( QgsGeometryOverlapCheck ) 96 : : public: 97 : : 98 : : /** 99 : : * Available resolution methods. 100 : : */ 101 : : enum ResolutionMethod 102 : : { 103 : : Subtract, //!< Subtract the overlap region from the polygon 104 : : NoChange //!< Do not change anything 105 : : }; 106 : : 107 : : /** 108 : : * Checks for overlapping polygons. 109 : : * 110 : : * In \a configuration a maxOverlapArea parameter can be passed. In case this parameter is set 111 : : * to something else than 0.0, the error will only be reported if the overlapping area is smaller 112 : : * than maxOverlapArea. 113 : : * Overlapping areas smaller than the reducedTolerance parameter of the \a context are ignored. 114 : : */ 115 : : QgsGeometryOverlapCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration ); 116 : 51 : QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return factoryCompatibleGeometryTypes(); } 117 : : void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override; 118 : : void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override; 119 : : Q_DECL_DEPRECATED QStringList resolutionMethods() const override; 120 : : 121 : : QString description() const override; 122 : : QString id() const override; 123 : : QgsGeometryCheck::Flags flags() const override; 124 : 0 : QgsGeometryCheck::CheckType checkType() const override { return factoryCheckType(); } 125 : : 126 : : ///@cond private 127 : : static QString factoryDescription() SIP_SKIP; 128 : : static QString factoryId() SIP_SKIP; 129 : : static QgsGeometryCheck::Flags factoryFlags() SIP_SKIP; 130 : : static QList<QgsWkbTypes::GeometryType> factoryCompatibleGeometryTypes() SIP_SKIP; 131 : : static bool factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP; 132 : : static QgsGeometryCheck::CheckType factoryCheckType() SIP_SKIP; 133 : : ///@endcond private 134 : : 135 : : private: 136 : : const double mOverlapThresholdMapUnits; 137 : : 138 : : }; 139 : : 140 : : #endif // QGS_GEOMETRY_OVERLAP_CHECK_H