Skip to content
Permalink
Browse files

Merge pull request #4800 from radosuav/release-2_18

[processing] fixes for zonal statistics algorithm
  • Loading branch information
alexbruy committed Jul 7, 2017
2 parents eb1a1d5 + 4886b36 commit 3d5124cf17f019c90c1b0b6a5a587753544ef122
Showing with 12 additions and 5 deletions.
  1. +12 −5 python/plugins/processing/algs/qgis/ZonalStatistics.py
@@ -89,6 +89,12 @@ def processAlgorithm(self, progress):
geoTransform = rasterDS.GetGeoTransform()
rasterBand = rasterDS.GetRasterBand(bandNumber)
noData = rasterBand.GetNoDataValue()
scale = rasterBand.GetScale()
if scale is None:
scale = 1.0
offset = rasterBand.GetOffset()
if offset is None:
offset = 0.0

cellXSize = abs(geoTransform[1])
cellYSize = abs(geoTransform[5])
@@ -118,7 +124,7 @@ def processAlgorithm(self, progress):

srcOffset = (startColumn, startRow, width, height)
srcArray = rasterBand.ReadAsArray(*srcOffset)
srcArray = srcArray * rasterBand.GetScale() + rasterBand.GetOffset()
srcArray = srcArray * scale + offset

newGeoTransform = (
geoTransform[0] + srcOffset[0] * geoTransform[1],
@@ -192,7 +198,7 @@ def processAlgorithm(self, progress):

srcOffset = (startColumn, startRow, width, height)
srcArray = rasterBand.ReadAsArray(*srcOffset)
srcArray = srcArray * rasterBand.GetScale() + rasterBand.GetOffset()
srcArray = srcArray * scale + offset

newGeoTransform = (
geoTransform[0] + srcOffset[0] * geoTransform[1],
@@ -219,10 +225,11 @@ def processAlgorithm(self, progress):
gdal.RasterizeLayer(rasterizedDS, [1], memLayer, burn_values=[1])
rasterizedArray = rasterizedDS.ReadAsArray()

srcArray = numpy.nan_to_num(srcArray)
masked = numpy.ma.MaskedArray(srcArray,
mask=numpy.logical_or(srcArray == noData,
numpy.logical_not(rasterizedArray)))
mask=numpy.logical_or.reduce((
srcArray == noData,
numpy.logical_not(rasterizedArray),
numpy.isnan(srcArray))))

outFeat.setGeometry(geom)

0 comments on commit 3d5124c

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