Bug report #14090
Frequency Analysis tool contains errors in code
| Status: | Closed | ||
|---|---|---|---|
| Priority: | Normal | ||
| Assignee: | |||
| Category: | Processing/Core | ||
| Affected QGIS version: | 2.12.0 | Regression?: | No |
| Operating System: | Easy fix?: | No | |
| Pull Request or Patch supplied: | No | Resolution: | |
| Crashes QGIS or corrupts data: | No | Copied to github as #: | 22098 |
Description
In the latest versions of the Processing plugin (from 2.10 onwards), there are minor errors in the code. The following code should probably be used to replace the existing code:
##Table=group
##Input=vector
##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) # Changed '(input)' to '(Input)'
inputFields = layer.pendingFields()
fieldIdxs = []
fields = Fields.split(',') # Changed 'fields.split' to 'Fields.split'
for f in fields:
idx = inputFields.indexFromName(f)
if idx == -1:
raise GeoAlgorithmExecutionException('Field not found:' + f)
fieldIdxs.append(idx)
writer = TableWriter(Frequency, None, fields + ['FREQ']) # Changed 'output' to 'Frequency'
counts = {}
feats = processing.features(layer)
nFeats = len(feats)
counts = defaultdict(int)
for i, feat in enumerate(feats):
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]])
This was reported from the GIS:Stack Exchange forum (http://gis.stackexchange.com/questions/171002/proper-use-of-qgis-tool-frequency-analysis)
Associated revisions
History
#1
Updated by Jürgen Fischer almost 10 years ago
- File diff
added
#2
Updated by Victor Olaya almost 10 years ago
- Status changed from Open to Closed
Fixed in changeset 7a879994d49ecbfeae406fce566015cab172b4d9.