Skip to content

Commit 845027d

Browse files
committed
Fix failing tests
1 parent 86002f3 commit 845027d

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

python/plugins/processing/algs/qgis/BasicStatistics.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,22 @@ def processAlgorithm(self, context, feedback):
131131

132132
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([field_name], layer.fields())
133133
features = QgsProcessingUtils.getFeatures(layer, context, request)
134+
count = QgsProcessingUtils.featureCount(layer, context)
134135

135136
data = []
136137
data.append(self.tr('Analyzed layer: {}').format(layer.name()))
137138
data.append(self.tr('Analyzed field: {}').format(field_name))
138139

139140
if field.isNumeric():
140-
data.extend(self.calcNumericStats(features, feedback, field))
141+
data.extend(self.calcNumericStats(features, feedback, field, count))
141142
elif field.type() in (QVariant.Date, QVariant.Time, QVariant.DateTime):
142-
data.extend(self.calcDateTimeStats(features, feedback, field))
143+
data.extend(self.calcDateTimeStats(features, feedback, field, count))
143144
else:
144-
data.extend(self.calcStringStats(features, feedback, field))
145+
data.extend(self.calcStringStats(features, feedback, field, count))
145146

146147
self.createHTML(output_file, data)
147148

148-
def calcNumericStats(self, features, feedback, field):
149-
count = QgsProcessingUtils.featureCount(layer, context)
149+
def calcNumericStats(self, features, feedback, field, count):
150150
total = 100.0 / float(count)
151151
stat = QgsStatisticalSummary()
152152
for current, ft in enumerate(features):
@@ -193,8 +193,7 @@ def calcNumericStats(self, features, feedback, field):
193193
data.append(self.tr('Interquartile Range (IQR): {}').format(stat.interQuartileRange()))
194194
return data
195195

196-
def calcStringStats(self, features, feedback, field):
197-
count = QgsProcessingUtils.featureCount(layer, context)
196+
def calcStringStats(self, features, feedback, field, count):
198197
total = 100.0 / float(count)
199198
stat = QgsStringStatisticalSummary()
200199
for current, ft in enumerate(features):
@@ -224,8 +223,7 @@ def calcStringStats(self, features, feedback, field):
224223

225224
return data
226225

227-
def calcDateTimeStats(self, features, feedback, field):
228-
count = QgsProcessingUtils.featureCount(layer, context)
226+
def calcDateTimeStats(self, features, feedback, field, count):
229227
total = 100.0 / float(count)
230228
stat = QgsDateTimeStatisticalSummary()
231229
for current, ft in enumerate(features):

python/plugins/processing/algs/qgis/FixGeometry.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def processAlgorithm(self, context, feedback):
7979
layer.crs())
8080

8181
features = QgsProcessingUtils.getFeatures(layer, context)
82-
if len(features) == 0:
82+
if QgsProcessingUtils.featureCount(layer, context) == 0:
8383
raise GeoAlgorithmExecutionException(self.tr('There are no features in the input layer'))
8484

8585
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)

python/plugins/processing/algs/qgis/PointDistance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def linearMatrix(self, context, inLayer, inField, targetLayer, targetField,
135135
distArea = QgsDistanceArea()
136136

137137
features = QgsProcessingUtils.getFeatures(inLayer, context)
138-
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
138+
total = 100.0 / QgsProcessingUtils.featureCount(inLayer, context)
139139
for current, inFeat in enumerate(features):
140140
inGeom = inFeat.geometry()
141141
inID = str(inFeat.attributes()[inIdx])

python/plugins/processing/algs/qgis/PolygonCentroids.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
from qgis.core import (QgsProcessingAlgorithm,
3333
QgsGeometry,
3434
QgsFeature,
35-
QgsWkbTypes)
35+
QgsWkbTypes,
36+
QgsProcessingUtils)
3637

3738
from processing.core.GeoAlgorithm import GeoAlgorithm
3839
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -83,7 +84,7 @@ def processAlgorithm(self, context, feedback):
8384
outFeat = QgsFeature()
8485

8586
features = QgsProcessingUtils.getFeatures(layer, context)
86-
total = 100.0 / len(features)
87+
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
8788
for current, feat in enumerate(features):
8889
inGeom = feat.geometry()
8990
attrs = feat.attributes()

python/plugins/processing/script/ScriptAlgorithm.py

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def processAlgorithm(self, context, feedback):
175175
ns = {}
176176
ns['feedback'] = feedback
177177
ns['scriptDescriptionFile'] = self.descriptionFile
178+
ns['context'] = context
178179

179180
for param in self.parameters:
180181
ns[param.name] = param.value

python/plugins/processing/tests/testdata/scripts/centroids.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##INPUT_LAYER=vector
44
##OUTPUT_LAYER=output vector
55

6-
from qgis.core import QgsWkbTypes, QgsGeometry
6+
from qgis.core import QgsWkbTypes, QgsGeometry, QgsProcessingUtils
77

88
from processing.tools.vector import VectorWriter
99
from processing.tools import dataobjects
@@ -13,12 +13,12 @@
1313

1414
writer = VectorWriter(OUTPUT_LAYER, 'utf-8', fields, QgsWkbTypes.Point, layer.crs())
1515

16-
features = processing.features(layer)
17-
count = len(features)
16+
features = QgsProcessingUtils.getFeatures(layer, context)
17+
count = QgsProcessingUtils.featureCount(layer, context)
1818
if count == 0:
1919
raise GeoAlgorithmExecutionException('Input layer contains no features.')
2020

21-
total = 100.0 / len(features)
21+
total = 100.0 / count
2222

2323
for count, f in enumerate(features):
2424
outputFeature = f

0 commit comments

Comments
 (0)