18
18
#include " qgsgeometryareacheck.h"
19
19
#include " ../utils/qgsfeaturepool.h"
20
20
21
- void QgsGeometryAreaCheck::collectErrors ( QList<QgsGeometryCheckError *> &errors, QStringList &/* messages*/ , QAtomicInt *progressCounter, const QgsFeatureIds &ids ) const
21
+ void QgsGeometryAreaCheck::collectErrors ( QList<QgsGeometryCheckError *> &errors, QStringList &/* messages*/ , QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
22
22
{
23
- const QgsFeatureIds & featureIds = ids.isEmpty () ? mFeaturePool -> getFeatureIds () : ids;
24
- Q_FOREACH ( QgsFeatureId featureid, featureIds )
23
+ QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty () ? allLayerFeatureIds () : ids;
24
+ for ( const QString &layerId : featureIds. keys () )
25
25
{
26
- if ( progressCounter ) progressCounter->fetchAndAddRelaxed ( 1 );
27
- QgsFeature feature;
28
- if ( !mFeaturePool ->get ( featureid, feature ) )
26
+ if ( !getCompatibility ( getFeaturePool ( layerId )->getLayer ()->geometryType () ) )
29
27
{
30
28
continue ;
31
29
}
32
-
33
- QgsGeometry g = feature.geometry ();
34
- QgsAbstractGeometry *geom = g.geometry ();
35
- if ( dynamic_cast <QgsGeometryCollection *>( geom ) )
30
+ for ( QgsFeatureId featureid : featureIds[layerId] )
36
31
{
37
- QgsGeometryCollection *multiGeom = static_cast <QgsGeometryCollection *>( geom );
38
- for ( int i = 0 , n = multiGeom->numGeometries (); i < n; ++i )
32
+ if ( progressCounter ) progressCounter->fetchAndAddRelaxed ( 1 );
33
+ QgsFeature feature;
34
+ if ( !getFeaturePool ( layerId )->get ( featureid, feature ) )
39
35
{
40
- double value;
41
- if ( checkThreshold ( multiGeom->geometryN ( i ), value ) )
36
+ continue ;
37
+ }
38
+
39
+ QgsGeometry g = feature.geometry ();
40
+ QgsAbstractGeometry *geom = g.geometry ();
41
+ if ( dynamic_cast <QgsGeometryCollection *>( geom ) )
42
+ {
43
+ QgsGeometryCollection *multiGeom = static_cast <QgsGeometryCollection *>( geom );
44
+ for ( int i = 0 , n = multiGeom->numGeometries (); i < n; ++i )
42
45
{
43
- errors.append ( new QgsGeometryCheckError ( this , featureid, multiGeom->geometryN ( i )->centroid (), QgsVertexId ( i ), value, QgsGeometryCheckError::ValueArea ) );
46
+ double value;
47
+ if ( checkThreshold ( layerId, multiGeom->geometryN ( i ), value ) )
48
+ {
49
+ errors.append ( new QgsGeometryCheckError ( this , layerId, featureid, multiGeom->geometryN ( i )->centroid (), QgsVertexId ( i ), value, QgsGeometryCheckError::ValueArea ) );
50
+ }
44
51
}
45
52
}
46
- }
47
- else
48
- {
49
- double value;
50
- if ( checkThreshold ( geom, value ) )
53
+ else
51
54
{
52
- errors.append ( new QgsGeometryCheckError ( this , featureid, geom->centroid (), QgsVertexId ( 0 ), value, QgsGeometryCheckError::ValueArea ) );
55
+ double value;
56
+ if ( checkThreshold ( layerId, geom, value ) )
57
+ {
58
+ errors.append ( new QgsGeometryCheckError ( this , layerId, featureid, geom->centroid (), QgsVertexId ( 0 ), value, QgsGeometryCheckError::ValueArea ) );
59
+ }
53
60
}
54
61
}
55
62
}
56
63
}
57
64
58
- void QgsGeometryAreaCheck::fixError ( QgsGeometryCheckError *error, int method, int mergeAttributeIndex , Changes &changes ) const
65
+ void QgsGeometryAreaCheck::fixError ( QgsGeometryCheckError *error, int method, const QMap<QString, int > &mergeAttributeIndices , Changes &changes ) const
59
66
{
60
67
QgsFeature feature;
61
- if ( !mFeaturePool ->get ( error->featureId (), feature ) )
68
+ if ( !getFeaturePool ( error-> layerId () ) ->get ( error->featureId (), feature ) )
62
69
{
63
70
error->setObsolete ();
64
71
return ;
@@ -78,7 +85,7 @@ void QgsGeometryAreaCheck::fixError( QgsGeometryCheckError *error, int method, i
78
85
if ( dynamic_cast <QgsGeometryCollection *>( geom ) )
79
86
{
80
87
double value;
81
- if ( !checkThreshold ( static_cast <QgsGeometryCollection *>( geom )->geometryN ( vidx.part ), value ) )
88
+ if ( !checkThreshold ( error-> layerId (), static_cast <QgsGeometryCollection *>( geom )->geometryN ( vidx.part ), value ) )
82
89
{
83
90
error->setObsolete ();
84
91
return ;
@@ -87,7 +94,7 @@ void QgsGeometryAreaCheck::fixError( QgsGeometryCheckError *error, int method, i
87
94
else
88
95
{
89
96
double value;
90
- if ( !checkThreshold ( geom, value ) )
97
+ if ( !checkThreshold ( error-> layerId (), geom, value ) )
91
98
{
92
99
error->setObsolete ();
93
100
return ;
@@ -101,13 +108,13 @@ void QgsGeometryAreaCheck::fixError( QgsGeometryCheckError *error, int method, i
101
108
}
102
109
else if ( method == Delete )
103
110
{
104
- deleteFeatureGeometryPart ( feature, vidx.part , changes );
111
+ deleteFeatureGeometryPart ( error-> layerId (), feature, vidx.part , changes );
105
112
error->setFixed ( method );
106
113
}
107
114
else if ( method == MergeLongestEdge || method == MergeLargestArea || method == MergeIdenticalAttribute )
108
115
{
109
116
QString errMsg;
110
- if ( mergeWithNeighbor ( feature, vidx.part , method, mergeAttributeIndex , changes, errMsg ) )
117
+ if ( mergeWithNeighbor ( error-> layerId (), feature, vidx.part , method, mergeAttributeIndices[error-> layerId ()] , changes, errMsg ) )
111
118
{
112
119
error->setFixed ( method );
113
120
}
@@ -122,20 +129,28 @@ void QgsGeometryAreaCheck::fixError( QgsGeometryCheckError *error, int method, i
122
129
}
123
130
}
124
131
125
- bool QgsGeometryAreaCheck::mergeWithNeighbor ( QgsFeature &feature, int partIdx, int method, int mergeAttributeIndex, Changes &changes, QString &errMsg ) const
132
+ bool QgsGeometryAreaCheck::checkThreshold ( const QString &layerId, const QgsAbstractGeometry *geom, double &value ) const
133
+ {
134
+ value = geom->area ();
135
+ double mapToLayerUnits = getFeaturePool ( layerId )->getMapToLayerUnits ();
136
+ double threshold = mThresholdMapUnits * mapToLayerUnits * mapToLayerUnits;
137
+ return value < threshold;
138
+ }
139
+
140
+ bool QgsGeometryAreaCheck::mergeWithNeighbor ( const QString &layerId, QgsFeature &feature, int partIdx, int method, int mergeAttributeIndex, Changes &changes, QString &errMsg ) const
126
141
{
127
142
double maxVal = 0 .;
128
143
QgsFeature mergeFeature;
129
144
int mergePartIdx = -1 ;
130
145
bool matchFound = false ;
131
- QgsGeometry g = feature.geometry ();;
146
+ QgsGeometry g = feature.geometry ();
132
147
QgsAbstractGeometry *geom = g.geometry ();
133
148
134
149
// Search for touching neighboring geometries
135
- Q_FOREACH ( QgsFeatureId testId, mFeaturePool ->getIntersects ( g.boundingBox () ) )
150
+ for ( QgsFeatureId testId : getFeaturePool ( layerId ) ->getIntersects ( g.boundingBox () ) )
136
151
{
137
152
QgsFeature testFeature;
138
- if ( !mFeaturePool ->get ( testId, testFeature ) )
153
+ if ( !getFeaturePool ( layerId ) ->get ( testId, testFeature ) )
139
154
{
140
155
continue ;
141
156
}
@@ -210,9 +225,9 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( QgsFeature &feature, int partIdx,
210
225
{
211
226
--mergePartIdx;
212
227
}
213
- replaceFeatureGeometryPart ( mergeFeature, mergePartIdx, combinedGeom, changes );
228
+ replaceFeatureGeometryPart ( layerId, mergeFeature, mergePartIdx, combinedGeom, changes );
214
229
// Remove polygon from source geometry
215
- deleteFeatureGeometryPart ( feature, partIdx, changes );
230
+ deleteFeatureGeometryPart ( layerId, feature, partIdx, changes );
216
231
217
232
return true ;
218
233
}
0 commit comments