Skip to content
Permalink
Browse files

Make zonal statistics algorithm thread safe

  • Loading branch information
nyalldawson committed Jun 8, 2018
1 parent b533dd8 commit fc5eb96295d0723a2686b77434db84950311a108
Showing with 17 additions and 8 deletions.
  1. +17 −8 python/plugins/processing/algs/qgis/ZonalStatistics.py
@@ -63,6 +63,14 @@ def groupId(self):

def __init__(self):
super().__init__()
self.bandNumber = None
self.columnPrefix = None
self.selectedStats = None
self.vectorLayer = None
self.raster_interface = None
self.raster_crs = None
self.raster_units_per_pixel_x = None
self.raster_units_per_pixel_y = None

def initAlgorithm(self, config=None):
self.STATS = OrderedDict([(self.tr('Count'), QgsZonalStatistics.Count),
@@ -99,12 +107,6 @@ def initAlgorithm(self, config=None):
self.tr('Zonal statistics'),
QgsProcessing.TypeVectorPolygon))

self.bandNumber = None
self.columnPrefix = None
self.selectedStats = None
self.vectorLayer = None
self.rasterLayer = None

def name(self):
return 'zonalstatistics'

@@ -122,12 +124,19 @@ def prepareAlgorithm(self, parameters, context, feedback):
self.selectedStats |= self.STATS[keys[i]]

self.vectorLayer = self.parameterAsVectorLayer(parameters, self.INPUT_VECTOR, context)
self.rasterLayer = self.parameterAsRasterLayer(parameters, self.INPUT_RASTER, context)
rasterLayer = self.parameterAsRasterLayer(parameters, self.INPUT_RASTER, context)
self.raster_interface = rasterLayer.dataProvider().clone()
self.raster_crs = rasterLayer.crs()
self.raster_units_per_pixel_x = rasterLayer.rasterUnitsPerPixelX()
self.raster_units_per_pixel_y = rasterLayer.rasterUnitsPerPixelY()
return True

def processAlgorithm(self, parameters, context, feedback):
zs = QgsZonalStatistics(self.vectorLayer,
self.rasterLayer,
self.raster_interface,
self.raster_crs,
self.raster_units_per_pixel_x,
self.raster_units_per_pixel_y,
self.columnPrefix,
self.bandNumber,
QgsZonalStatistics.Statistics(self.selectedStats))

0 comments on commit fc5eb96

Please sign in to comment.
You can’t perform that action at this time.