1 /***************************************************************************
2     qgsgeometryareacheck.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_AREA_CHECK_H
19 #define QGS_GEOMETRY_AREA_CHECK_H
20 
21 #include "qgsgeometrycheck.h"
22 
23 class QgsSurface;
24 
25 /**
26  * \ingroup analysis
27  * \brief Area check.
28  */
29 class ANALYSIS_EXPORT QgsGeometryAreaCheck : public QgsGeometryCheck
30 {
31     Q_DECLARE_TR_FUNCTIONS( QgsGeometryAreaCheck )
32   public:
33     enum ResolutionMethod { MergeLongestEdge, MergeLargestArea, MergeIdenticalAttribute, Delete, NoChange };
34 
QgsGeometryAreaCheck(QgsGeometryCheckContext * context,const QVariantMap & configuration)35     QgsGeometryAreaCheck( QgsGeometryCheckContext *context, const QVariantMap &configuration )
36       : QgsGeometryCheck( context, configuration )
37       , mAreaThreshold( configurationValue<double>( "areaThreshold" ) )
38     {}
compatibleGeometryTypes()39     QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return factoryCompatibleGeometryTypes(); }
40     void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
41     void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
42     Q_DECL_DEPRECATED QStringList resolutionMethods() const override;
id()43     QString id() const override { return factoryId(); }
checkType()44     QgsGeometryCheck::CheckType checkType() const override { return factoryCheckType(); }
45 
factoryCompatibleGeometryTypes()46     static QList<QgsWkbTypes::GeometryType> factoryCompatibleGeometryTypes() {return {QgsWkbTypes::PolygonGeometry}; }
factoryIsCompatible(QgsVectorLayer * layer)47     static bool factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP { return factoryCompatibleGeometryTypes().contains( layer->geometryType() ); }
factoryDescription()48     static QString factoryDescription() { return tr( "Minimal area" ); }
description()49     QString description() const override { return factoryDescription(); }
factoryId()50     static QString factoryId() { return QStringLiteral( "QgsGeometryAreaCheck" ); }
factoryCheckType()51     static QgsGeometryCheck::CheckType factoryCheckType() { return QgsGeometryCheck::FeatureCheck; }
52 
53   private:
54     virtual bool checkThreshold( double layerToMapUnits, const QgsAbstractGeometry *geom, double &value ) const;
55     bool mergeWithNeighbor( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, int method, int mergeAttributeIndex, Changes &changes, QString &errMsg ) const;
56 
57     const double mAreaThreshold;
58 };
59 
60 #endif // QGS_GEOMETRY_AREA_CHECK_H
61