2014-10-03 10:41:44 +02:00
|
|
|
##Table=group
|
2015-05-22 15:56:45 +02:00
|
|
|
##Input=vector
|
|
|
|
##Fields=string
|
|
|
|
##Frequency=output table
|
2014-07-10 22:35:40 +02:00
|
|
|
|
2015-01-09 19:02:50 +00:00
|
|
|
from processing.tools.vector import TableWriter
|
2014-07-10 22:35:40 +02:00
|
|
|
from collections import defaultdict
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
2014-07-10 22:35:40 +02:00
|
|
|
|
2014-10-03 10:41:44 +02:00
|
|
|
layer = processing.getObject(input)
|
2014-07-10 22:35:40 +02:00
|
|
|
inputFields = layer.pendingFields()
|
|
|
|
fieldIdxs = []
|
2014-10-03 10:41:44 +02:00
|
|
|
fields = fields.split(',')
|
2014-10-19 15:52:38 +02:00
|
|
|
for f in fields:
|
|
|
|
idx = inputFields.indexFromName(f)
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
if idx == -1:
|
2014-07-10 22:35:40 +02:00
|
|
|
raise GeoAlgorithmExecutionException('Field not found:' + f)
|
|
|
|
fieldIdxs.append(idx)
|
2015-08-22 14:29:41 +02:00
|
|
|
writer = TableWriter(output, None, fields + ['FREQ'])
|
2014-07-10 22:35:40 +02:00
|
|
|
|
|
|
|
counts = {}
|
|
|
|
feats = processing.features(layer)
|
|
|
|
nFeats = len(feats)
|
|
|
|
counts = defaultdict(int)
|
|
|
|
for i, feat in enumerate(feats):
|
2014-10-19 15:52:38 +02:00
|
|
|
progress.setPercentage(int(100 * i / nFeats))
|
2014-07-10 22:35:40 +02:00
|
|
|
attrs = feat.attributes()
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
clazz = tuple([attrs[i] for i in fieldIdxs])
|
2014-10-03 10:41:44 +02:00
|
|
|
print clazz
|
2014-07-10 22:35:40 +02:00
|
|
|
counts[clazz] += 1
|
|
|
|
|
2014-10-19 15:52:38 +02:00
|
|
|
for c in counts:
|
2014-07-10 22:35:40 +02:00
|
|
|
writer.addRecord(list(c) + [counts[c]])
|