Skip to content
Permalink
Browse files

[processing] fixed frequency analysis algorithm

code provided by Joseph Liam

fixes #14090
  • Loading branch information
volaya committed Jan 13, 2016
1 parent b2cc309 commit 7a879994d49ecbfeae406fce566015cab172b4d9
Showing with 5 additions and 6 deletions.
  1. +5 −6 python/plugins/processing/algs/qgis/scripts/Frequency_analysis.py
@@ -1,22 +1,22 @@
##Table=group
##Input=vector
##Fields=string
##Fields=Field Input
##Frequency=output table

from processing.tools.vector import TableWriter
from collections import defaultdict
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

layer = processing.getObject(input)
layer = processing.getObject(Input)
inputFields = layer.pendingFields()
fieldIdxs = []
fields = fields.split(',')
fields = Fields.split(',')
for f in fields:
idx = inputFields.indexFromName(f)
if idx == -1:
raise GeoAlgorithmExecutionException('Field not found:' + f)
fieldIdxs.append(idx)
writer = TableWriter(output, None, fields + ['FREQ'])
writer = TableWriter(Frequency, None, fields + ['FREQ'])

counts = {}
feats = processing.features(layer)
@@ -26,8 +26,7 @@
progress.setPercentage(int(100 * i / nFeats))
attrs = feat.attributes()
clazz = tuple([attrs[i] for i in fieldIdxs])
print clazz
counts[clazz] += 1

for c in counts:
writer.addRecord(list(c) + [counts[c]])
writer.addRecord(list(c) + [counts[c]])

0 comments on commit 7a87999

Please sign in to comment.
You can’t perform that action at this time.