summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Wiesmann <yellowcap@users.noreply.github.com>2016-05-16 17:43:04 +0100
committerClaude Paroz <claude@2xlibre.net>2016-05-16 18:43:04 +0200
commit078eb876261fdf8793b201c4d17e67f515bd4de9 (patch)
tree8c9a27f442c39e13191b97606d2c83680c3675d9
parentaa69f36984adb6cba5763604150d99e89aa1ee71 (diff)
Refs #26592 -- Fixed band statistics for empty bands and GDAL 2.1
-rw-r--r--django/contrib/gis/gdal/prototypes/raster.py2
-rw-r--r--django/contrib/gis/gdal/raster/band.py14
2 files changed, 7 insertions, 9 deletions
diff --git a/django/contrib/gis/gdal/prototypes/raster.py b/django/contrib/gis/gdal/prototypes/raster.py
index 1002344292..8641b86b44 100644
--- a/django/contrib/gis/gdal/prototypes/raster.py
+++ b/django/contrib/gis/gdal/prototypes/raster.py
@@ -74,12 +74,10 @@ get_band_statistics = void_output(
c_void_p, c_int, c_int, POINTER(c_double), POINTER(c_double),
POINTER(c_double), POINTER(c_double), c_void_p, c_void_p,
],
- errcheck=False
)
compute_band_statistics = void_output(
std_call('GDALComputeRasterStatistics'),
[c_void_p, c_int, POINTER(c_double), POINTER(c_double), POINTER(c_double), POINTER(c_double), c_void_p, c_void_p],
- errcheck=False
)
# Reprojection routine
diff --git a/django/contrib/gis/gdal/raster/band.py b/django/contrib/gis/gdal/raster/band.py
index 878cc5aa4a..bb65cf197e 100644
--- a/django/contrib/gis/gdal/raster/band.py
+++ b/django/contrib/gis/gdal/raster/band.py
@@ -1,4 +1,3 @@
-import math
from ctypes import byref, c_double, c_int, c_void_p
from django.contrib.gis.gdal.base import GDALBase
@@ -85,18 +84,19 @@ class GDALBand(GDALBase):
]
if refresh or self._stats_refresh:
- capi.compute_band_statistics(*stats_args)
+ func = capi.compute_band_statistics
else:
# Add additional argument to force computation if there is no
# existing PAM file to take the values from.
force = True
stats_args.insert(2, c_int(force))
- capi.get_band_statistics(*stats_args)
+ func = capi.get_band_statistics
- result = smin.value, smax.value, smean.value, sstd.value
-
- # Check if band is empty (in that case, set all statistics to None)
- if any((math.isnan(val) for val in result)):
+ # Computation of statistics fails for empty bands.
+ try:
+ func(*stats_args)
+ result = smin.value, smax.value, smean.value, sstd.value
+ except GDALException:
result = (None, None, None, None)
self._stats_refresh = False