Skip to content
Permalink
Browse files
Fix failing tests
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent 86002f3 commit 845027d0a35689fd518ba8d7b5f40a7f8e42941d
@@ -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):
@@ -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):
@@ -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):
@@ -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)
@@ -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])
@@ -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
@@ -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()
@@ -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
@@ -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
@@ -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

0 comments on commit 845027d

Please sign in to comment.