Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent 86002f3 commit 845027d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
16 changes: 7 additions & 9 deletions python/plugins/processing/algs/qgis/BasicStatistics.py
Expand Up @@ -131,22 +131,22 @@ def processAlgorithm(self, context, feedback):

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

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

if field.isNumeric():
data.extend(self.calcNumericStats(features, feedback, field))
data.extend(self.calcNumericStats(features, feedback, field, count))
elif field.type() in (QVariant.Date, QVariant.Time, QVariant.DateTime):
data.extend(self.calcDateTimeStats(features, feedback, field))
data.extend(self.calcDateTimeStats(features, feedback, field, count))
else:
data.extend(self.calcStringStats(features, feedback, field))
data.extend(self.calcStringStats(features, feedback, field, count))

self.createHTML(output_file, data)

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

def calcStringStats(self, features, feedback, field):
count = QgsProcessingUtils.featureCount(layer, context)
def calcStringStats(self, features, feedback, field, count):
total = 100.0 / float(count)
stat = QgsStringStatisticalSummary()
for current, ft in enumerate(features):
Expand Down Expand Up @@ -224,8 +223,7 @@ def calcStringStats(self, features, feedback, field):

return data

def calcDateTimeStats(self, features, feedback, field):
count = QgsProcessingUtils.featureCount(layer, context)
def calcDateTimeStats(self, features, feedback, field, count):
total = 100.0 / float(count)
stat = QgsDateTimeStatisticalSummary()
for current, ft in enumerate(features):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/FixGeometry.py
Expand Up @@ -79,7 +79,7 @@ def processAlgorithm(self, context, feedback):
layer.crs())

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

total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/PointDistance.py
Expand Up @@ -135,7 +135,7 @@ def linearMatrix(self, context, inLayer, inField, targetLayer, targetField,
distArea = QgsDistanceArea()

features = QgsProcessingUtils.getFeatures(inLayer, context)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
total = 100.0 / QgsProcessingUtils.featureCount(inLayer, context)
for current, inFeat in enumerate(features):
inGeom = inFeat.geometry()
inID = str(inFeat.attributes()[inIdx])
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/PolygonCentroids.py
Expand Up @@ -32,7 +32,8 @@
from qgis.core import (QgsProcessingAlgorithm,
QgsGeometry,
QgsFeature,
QgsWkbTypes)
QgsWkbTypes,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
Expand Down Expand Up @@ -83,7 +84,7 @@ def processAlgorithm(self, context, feedback):
outFeat = QgsFeature()

features = QgsProcessingUtils.getFeatures(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, feat in enumerate(features):
inGeom = feat.geometry()
attrs = feat.attributes()
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/script/ScriptAlgorithm.py
Expand Up @@ -175,6 +175,7 @@ def processAlgorithm(self, context, feedback):
ns = {}
ns['feedback'] = feedback
ns['scriptDescriptionFile'] = self.descriptionFile
ns['context'] = context

for param in self.parameters:
ns[param.name] = param.value
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/tests/testdata/scripts/centroids.py
Expand Up @@ -3,7 +3,7 @@
##INPUT_LAYER=vector
##OUTPUT_LAYER=output vector

from qgis.core import QgsWkbTypes, QgsGeometry
from qgis.core import QgsWkbTypes, QgsGeometry, QgsProcessingUtils

from processing.tools.vector import VectorWriter
from processing.tools import dataobjects
Expand All @@ -13,12 +13,12 @@

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

features = processing.features(layer)
count = len(features)
features = QgsProcessingUtils.getFeatures(layer, context)
count = QgsProcessingUtils.featureCount(layer, context)
if count == 0:
raise GeoAlgorithmExecutionException('Input layer contains no features.')

total = 100.0 / len(features)
total = 100.0 / count

for count, f in enumerate(features):
outputFeature = f
Expand Down

0 comments on commit 845027d

Please sign in to comment.