Skip to content

Commit

Permalink
[processing] updated freq analysis alg
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Oct 3, 2014
1 parent 558765a commit ac54c8e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions python/plugins/processing/algs/qgis/scripts/Frequency_analysis.py
Original file line number Diff line number Diff line change
@@ -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.