Skip to content
Permalink
Browse files

[processing] don't write NaN's to attribute table (fix #14639)

  • Loading branch information
alexbruy committed Apr 26, 2016
1 parent 63c71fe commit 77d95b0d655022ab5c9f1927fa0a8ddb492b44df
Showing with 16 additions and 8 deletions.
  1. +16 −8 python/plugins/processing/algs/qgis/ZonalStatistics.py
@@ -227,16 +227,24 @@ def processAlgorithm(self, progress):
outFeat.setGeometry(geom)

attrs = f.attributes()
attrs.insert(idxMin, float(masked.min()))
attrs.insert(idxMax, float(masked.max()))
attrs.insert(idxSum, float(masked.sum()))
v = float(masked.min())
attrs.insert(idxMin, None if numpy.isnan(v) else v)
v = float(masked.max())
attrs.insert(idxMax, None if numpy.isnan(v) else v)
v = float(masked.sum())
attrs.insert(idxSum, None if numpy.isnan(v) else v)
attrs.insert(idxCount, int(masked.count()))
attrs.insert(idxMean, float(masked.mean()))
attrs.insert(idxStd, float(masked.std()))
v = float(masked.mean())
attrs.insert(idxMean, None if numpy.isnan(v) else v)
v = float(masked.std())
attrs.insert(idxStd, None if numpy.isnan(v) else v)
attrs.insert(idxUnique, numpy.unique(masked.compressed()).size)
attrs.insert(idxRange, float(masked.max()) - float(masked.min()))
attrs.insert(idxVar, float(masked.var()))
attrs.insert(idxMedian, float(numpy.ma.median(masked)))
v = float(masked.max()) - float(masked.min())
attrs.insert(idxRange, None if numpy.isnan(v) else v)
v = float(masked.var())
attrs.insert(idxVar, None if numpy.isnan(v) else v)
v = float(numpy.ma.median(masked))
attrs.insert(idxMedian, None if numpy.isnan(v) else v)
if hasSciPy:
attrs.insert(idxMode, float(mode(masked, axis=None)[0][0]))

0 comments on commit 77d95b0

Please sign in to comment.