Skip to content
Permalink
Browse files

[processing] updated freq analysis alg

  • Loading branch information
volaya committed Oct 3, 2014
1 parent 558765a commit ac54c8e00ae123a59b0c6f68f1fa18f8e62bff63
Showing with 13 additions and 11 deletions.
  1. +13 −11 python/plugins/processing/algs/qgis/scripts/Frequency_analysis.py
@@ -1,33 +1,35 @@
##Vector table tools=group
##Input=vector
##Fields=string
##Output=output table
##Table=group
##input=vector
##fields=string
##output=output table

from qgis.core import *
from PyQt4.QtCore import *
from processing.core.TableWriter import TableWriter
from collections import defaultdict

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

counts = {}
feats = processing.features(layer)
nFeats = len(feats)
counts = defaultdict(int)
for i, feat in enumerate(feats):
progress.setPercentage(int(100 * i / nFeats))
progress.setPercentage(int(100 * i / nFeats))
attrs = feat.attributes()
clazz = tuple([attrs[idx] for idx in fieldIdxs])
print clazz
counts[clazz] += 1

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

0 comments on commit ac54c8e

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