Fixed #25533 -- Changed datatype mapping for GDALRasters
This commit is contained in:
parent
37d06cfc46
commit
5d8985005e
|
@ -2,7 +2,7 @@
|
||||||
GDAL - Constant definitions
|
GDAL - Constant definitions
|
||||||
"""
|
"""
|
||||||
from ctypes import (
|
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
|
# See http://www.gdal.org/gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4
|
||||||
|
@ -29,7 +29,7 @@ GDAL_INTEGER_TYPES = [1, 2, 3, 4, 5]
|
||||||
# or to hold the space for data to be read into. The lookup below helps
|
# 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.
|
# selecting the right ctypes object for a given gdal pixel type.
|
||||||
GDAL_TO_CTYPES = [
|
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
|
c_float, c_double, None, None, None, None
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,27 @@ class GDALRasterTests(unittest.TestCase):
|
||||||
self.assertEqual(len(self.rs.bands), 1)
|
self.assertEqual(len(self.rs.bands), 1)
|
||||||
self.assertIsInstance(self.rs.bands[0], GDALBand)
|
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):
|
def test_file_based_raster_creation(self):
|
||||||
# Prepare tempfile
|
# Prepare tempfile
|
||||||
rstfile = tempfile.NamedTemporaryFile(suffix='.tif')
|
rstfile = tempfile.NamedTemporaryFile(suffix='.tif')
|
||||||
|
|
Loading…
Reference in New Issue