summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/contrib/gis/gdal/prototypes/raster.py1
-rw-r--r--django/contrib/gis/gdal/raster/band.py11
-rw-r--r--django/contrib/gis/gdal/raster/const.py21
3 files changed, 32 insertions, 1 deletions
diff --git a/django/contrib/gis/gdal/prototypes/raster.py b/django/contrib/gis/gdal/prototypes/raster.py
index 72702ab178..14cb512245 100644
--- a/django/contrib/gis/gdal/prototypes/raster.py
+++ b/django/contrib/gis/gdal/prototypes/raster.py
@@ -75,6 +75,7 @@ get_band_index = int_output(std_call('GDALGetBandNumber'), [c_void_p])
get_band_description = const_string_output(std_call('GDALGetDescription'), [c_void_p])
get_band_ds = voidptr_output(std_call('GDALGetBandDataset'), [c_void_p])
get_band_datatype = int_output(std_call('GDALGetRasterDataType'), [c_void_p])
+get_band_color_interp = int_output(std_call('GDALGetRasterColorInterpretation'), [c_void_p])
get_band_nodata_value = double_output(std_call('GDALGetRasterNoDataValue'), [c_void_p, POINTER(c_int)])
set_band_nodata_value = void_output(std_call('GDALSetRasterNoDataValue'), [c_void_p, c_double])
if GDAL_VERSION >= (2, 1):
diff --git a/django/contrib/gis/gdal/raster/band.py b/django/contrib/gis/gdal/raster/band.py
index 19d8ef41cf..d78fd2213e 100644
--- a/django/contrib/gis/gdal/raster/band.py
+++ b/django/contrib/gis/gdal/raster/band.py
@@ -6,7 +6,9 @@ from django.contrib.gis.gdal.raster.base import GDALRasterBase
from django.contrib.gis.shortcuts import numpy
from django.utils.encoding import force_text
-from .const import GDAL_INTEGER_TYPES, GDAL_PIXEL_TYPES, GDAL_TO_CTYPES
+from .const import (
+ GDAL_COLOR_TYPES, GDAL_INTEGER_TYPES, GDAL_PIXEL_TYPES, GDAL_TO_CTYPES,
+)
class GDALBand(GDALRasterBase):
@@ -168,6 +170,13 @@ class GDALBand(GDALRasterBase):
dtype = GDAL_PIXEL_TYPES[dtype]
return dtype
+ def color_interp(self, as_string=False):
+ """Return the GDAL color interpretation for this band."""
+ color = capi.get_band_color_interp(self._ptr)
+ if as_string:
+ color = GDAL_COLOR_TYPES[color]
+ return color
+
def data(self, data=None, offset=None, size=None, shape=None, as_memoryview=False):
"""
Read or writes pixel values for this band. Blocks of data can
diff --git a/django/contrib/gis/gdal/raster/const.py b/django/contrib/gis/gdal/raster/const.py
index 8b2656d33f..3c87499b87 100644
--- a/django/contrib/gis/gdal/raster/const.py
+++ b/django/contrib/gis/gdal/raster/const.py
@@ -44,6 +44,27 @@ GDAL_RESAMPLE_ALGORITHMS = {
'Mode': 6,
}
+# See http://www.gdal.org/gdal_8h.html#ace76452d94514561fffa8ea1d2a5968c
+GDAL_COLOR_TYPES = {
+ 0: 'GCI_Undefined', # Undefined, default value, i.e. not known
+ 1: 'GCI_GrayIndex', # Greyscale
+ 2: 'GCI_PaletteIndex', # Paletted
+ 3: 'GCI_RedBand', # Red band of RGBA image
+ 4: 'GCI_GreenBand', # Green band of RGBA image
+ 5: 'GCI_BlueBand', # Blue band of RGBA image
+ 6: 'GCI_AlphaBand', # Alpha (0=transparent, 255=opaque)
+ 7: 'GCI_HueBand', # Hue band of HLS image
+ 8: 'GCI_SaturationBand', # Saturation band of HLS image
+ 9: 'GCI_LightnessBand', # Lightness band of HLS image
+ 10: 'GCI_CyanBand', # Cyan band of CMYK image
+ 11: 'GCI_MagentaBand', # Magenta band of CMYK image
+ 12: 'GCI_YellowBand', # Yellow band of CMYK image
+ 13: 'GCI_BlackBand', # Black band of CMLY image
+ 14: 'GCI_YCbCr_YBand', # Y Luminance
+ 15: 'GCI_YCbCr_CbBand', # Cb Chroma
+ 16: 'GCI_YCbCr_CrBand', # Cr Chroma, also GCI_Max
+}
+
# Fixed base path for buffer-based GDAL in-memory files.
VSI_FILESYSTEM_BASE_PATH = '/vsimem/'