mirror of https://github.com/django/django.git
Refs #26592 -- Fixed band statistics for empty bands and GDAL 2.1
This commit is contained in:
parent
aa69f36984
commit
078eb87626
|
@ -74,12 +74,10 @@ get_band_statistics = void_output(
|
||||||
c_void_p, c_int, c_int, POINTER(c_double), POINTER(c_double),
|
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,
|
POINTER(c_double), POINTER(c_double), c_void_p, c_void_p,
|
||||||
],
|
],
|
||||||
errcheck=False
|
|
||||||
)
|
)
|
||||||
compute_band_statistics = void_output(
|
compute_band_statistics = void_output(
|
||||||
std_call('GDALComputeRasterStatistics'),
|
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],
|
[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
|
# Reprojection routine
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import math
|
|
||||||
from ctypes import byref, c_double, c_int, c_void_p
|
from ctypes import byref, c_double, c_int, c_void_p
|
||||||
|
|
||||||
from django.contrib.gis.gdal.base import GDALBase
|
from django.contrib.gis.gdal.base import GDALBase
|
||||||
|
@ -85,18 +84,19 @@ class GDALBand(GDALBase):
|
||||||
]
|
]
|
||||||
|
|
||||||
if refresh or self._stats_refresh:
|
if refresh or self._stats_refresh:
|
||||||
capi.compute_band_statistics(*stats_args)
|
func = capi.compute_band_statistics
|
||||||
else:
|
else:
|
||||||
# Add additional argument to force computation if there is no
|
# Add additional argument to force computation if there is no
|
||||||
# existing PAM file to take the values from.
|
# existing PAM file to take the values from.
|
||||||
force = True
|
force = True
|
||||||
stats_args.insert(2, c_int(force))
|
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
|
# Computation of statistics fails for empty bands.
|
||||||
|
try:
|
||||||
# Check if band is empty (in that case, set all statistics to None)
|
func(*stats_args)
|
||||||
if any((math.isnan(val) for val in result)):
|
result = smin.value, smax.value, smean.value, sstd.value
|
||||||
|
except GDALException:
|
||||||
result = (None, None, None, None)
|
result = (None, None, None, None)
|
||||||
|
|
||||||
self._stats_refresh = False
|
self._stats_refresh = False
|
||||||
|
|
Loading…
Reference in New Issue