-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] updated freq analysis alg
- Loading branch information
Showing
1 changed file
with
13 additions
and
11 deletions.
There are no files selected for viewing
24 changes: 13 additions & 11 deletions
24
python/plugins/processing/algs/qgis/scripts/Frequency_analysis.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]]) | ||
|