Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequency Analysis tool contains errors in code #22098

Closed
qgib opened this issue Jan 12, 2016 · 2 comments
Closed

Frequency Analysis tool contains errors in code #22098

qgib opened this issue Jan 12, 2016 · 2 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Processing Relating to QGIS Processing framework or individual Processing algorithms

Comments

@qgib
Copy link
Contributor

qgib commented Jan 12, 2016

Author Name: Joseph Liam (Joseph Liam)
Original Redmine Issue: 14090
Affected QGIS version: 2.12.0
Redmine category:processing/core
Assignee: Victor Olaya


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)


  • diff (Jürgen Fischer)
@qgib
Copy link
Contributor Author

qgib commented Jan 12, 2016

Author Name: Jürgen Fischer (@jef-n)


  • 9464 was configured as diff

  • diff (Jürgen Fischer)

@qgib
Copy link
Contributor Author

qgib commented Jan 12, 2016

Author Name: Victor Olaya (@volaya)


Fixed in changeset "7a879994d49ecbfeae406fce566015cab172b4d9".


  • status_id was changed from Open to Closed

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Processing Relating to QGIS Processing framework or individual Processing algorithms labels May 25, 2019
@qgib qgib closed this as completed May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Processing Relating to QGIS Processing framework or individual Processing algorithms
Projects
None yet
Development

No branches or pull requests

1 participant