2014-10-03 10:41:44 +02:00
|
|
|
##Table=group
|
2015-05-22 15:56:45 +02:00
|
|
|
##Input=vector
|
2016-01-13 09:55:30 +01:00
|
|
|
##Fields=Field Input
|
2015-05-22 15:56:45 +02:00
|
|
|
##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
|
2017-04-26 13:13:08 +10:00
|
|
|
from qgis.core import QgsProcessingUtils
|
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
|
|
|
|
2017-05-02 13:40:49 +10:00
|
|
|
layer = QgsProcessingUtils.mapLayerFromString(Input, context)
|
2016-08-04 07:37:22 +10:00
|
|
|
inputFields = layer.fields()
|
2014-07-10 22:35:40 +02:00
|
|
|
fieldIdxs = []
|
2016-01-13 09:55:30 +01: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)
|
2016-01-13 09:55:30 +01:00
|
|
|
writer = TableWriter(Frequency, None, fields + ['FREQ'])
|
2014-07-10 22:35:40 +02:00
|
|
|
|
|
|
|
counts = {}
|
2017-04-26 13:13:08 +10:00
|
|
|
feats = QgsProcessingUtils.getFeatures(layer, context)
|
|
|
|
nFeats = QgsProcessingUtils.featureCount(layer, context)
|
2014-07-10 22:35:40 +02:00
|
|
|
counts = defaultdict(int)
|
|
|
|
for i, feat in enumerate(feats):
|
2017-01-06 20:04:00 +10:00
|
|
|
feedback.setProgress(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-07-10 22:35:40 +02:00
|
|
|
counts[clazz] += 1
|
|
|
|
|
2014-10-19 15:52:38 +02:00
|
|
|
for c in counts:
|
2016-01-14 08:57:04 +11:00
|
|
|
writer.addRecord(list(c) + [counts[c]])
|