Skip to content

Commit

Permalink
[1.9.x] Fixed #25533 -- Changed datatype mapping for GDALRasters
Browse files Browse the repository at this point in the history
Backport of 5d89850 from master.
  • Loading branch information
yellowcap authored and claudep committed Oct 9, 2015
1 parent 2c11002 commit 4326ac6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django/contrib/gis/gdal/raster/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
GDAL - Constant definitions
"""
from ctypes import (
c_byte, c_double, c_float, c_int16, c_int32, c_uint16, c_uint32,
c_double, c_float, c_int16, c_int32, c_ubyte, c_uint16, c_uint32,
)

# See http://www.gdal.org/gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4
Expand All @@ -29,7 +29,7 @@
# or to hold the space for data to be read into. The lookup below helps
# selecting the right ctypes object for a given gdal pixel type.
GDAL_TO_CTYPES = [
None, c_byte, c_uint16, c_int16, c_uint32, c_int32,
None, c_ubyte, c_uint16, c_int16, c_uint32, c_int32,
c_float, c_double, None, None, None, None
]

Expand Down
21 changes: 21 additions & 0 deletions tests/gis_tests/gdal_tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ def test_rs_bands(self):
self.assertEqual(len(self.rs.bands), 1)
self.assertIsInstance(self.rs.bands[0], GDALBand)

def test_memory_based_raster_creation(self):
# Create uint8 raster with full pixel data range (0-255)
rast = GDALRaster({
'datatype': 1,
'width': 16,
'height': 16,
'srid': 4326,
'bands': [{
'data': range(256),
'nodata_value': 255,
}],
})

# Get array from raster
result = rast.bands[0].data()
if numpy:
result = result.flatten().tolist()

# Assert data is same as original input
self.assertEqual(result, list(range(256)))

def test_file_based_raster_creation(self):
# Prepare tempfile
rstfile = tempfile.NamedTemporaryFile(suffix='.tif')
Expand Down

0 comments on commit 4326ac6

Please sign in to comment.