Skip to content

Commit

Permalink
Keep correct order for zonal stats options, set some stats by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 4eca20f commit 4fa2bc0
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions python/plugins/processing/algs/qgis/ZonalStatistics.py
Expand Up @@ -26,6 +26,7 @@
__revision__ = '$Format:%H$'

import os
from collections import OrderedDict

from qgis.PyQt.QtGui import QIcon

Expand Down Expand Up @@ -61,20 +62,19 @@ def group(self):

def __init__(self):
super().__init__()
self.STATS = {self.tr('Count'): QgsZonalStatistics.Count,
self.tr('Sum'): QgsZonalStatistics.Sum,
self.tr('Mean'): QgsZonalStatistics.Mean,
self.tr('Median'): QgsZonalStatistics.Median,
self.tr('Std. dev.'): QgsZonalStatistics.StDev,
self.tr('Min'): QgsZonalStatistics.Min,
self.tr('Max'): QgsZonalStatistics.Max,
self.tr('Range'): QgsZonalStatistics.Range,
self.tr('Minority'): QgsZonalStatistics.Minority,
self.tr('Majority (mode)'): QgsZonalStatistics.Majority,
self.tr('Variety'): QgsZonalStatistics.Variety,
self.tr('Variance'): QgsZonalStatistics.Variance,
self.tr('All'): QgsZonalStatistics.All
}
self.STATS = OrderedDict([(self.tr('Count'), QgsZonalStatistics.Count),
(self.tr('Sum'), QgsZonalStatistics.Sum),
(self.tr('Mean'), QgsZonalStatistics.Mean),
(self.tr('Median'), QgsZonalStatistics.Median),
(self.tr('Std. dev.'), QgsZonalStatistics.StDev),
(self.tr('Min'), QgsZonalStatistics.Min),
(self.tr('Max'), QgsZonalStatistics.Max),
(self.tr('Range'), QgsZonalStatistics.Range),
(self.tr('Minority'), QgsZonalStatistics.Minority),
(self.tr('Majority (mode)'), QgsZonalStatistics.Majority),
(self.tr('Variety'), QgsZonalStatistics.Variety),
(self.tr('Variance'), QgsZonalStatistics.Variance),
(self.tr('All'), QgsZonalStatistics.All)])

self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT_RASTER,
self.tr('Raster layer')))
Expand All @@ -86,10 +86,11 @@ def __init__(self):
[QgsProcessingParameterDefinition.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterString(self.COLUMN_PREFIX,
self.tr('Output column prefix'), '_'))
keys = list(self.STATS.keys())
self.addParameter(QgsProcessingParameterEnum(self.STATISTICS,
self.tr('Statistics to calculate'),
list(self.STATS.keys()),
allowMultiple=True))
keys,
allowMultiple=True, defaultValue=[0,1,2]))
self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT_VECTOR,
self.tr('Zonal statistics'),
QgsProcessingParameterDefinition.TypeVectorPolygon))
Expand Down

0 comments on commit 4fa2bc0

Please sign in to comment.