diff --git a/autotest/gdrivers/vrtderived.py b/autotest/gdrivers/vrtderived.py index e02b4c459f37..220dae91ec64 100755 --- a/autotest/gdrivers/vrtderived.py +++ b/autotest/gdrivers/vrtderived.py @@ -1023,6 +1023,59 @@ def identity(in_ar, out_ar, xoff, yoff, xsize, ysize, raster_xsize, raster_ysize _validate(xml) +############################################################################### + + +@pytest.mark.parametrize( + "dtype", + ( + gdal.GDT_Int8, + gdal.GDT_Byte, + gdal.GDT_Int16, + gdal.GDT_UInt16, + gdal.GDT_Int32, + gdal.GDT_UInt32, + gdal.GDT_Int64, + gdal.GDT_UInt64, + ), +) +def test_vrt_derived_dtype(tmp_vsimem, dtype): + input_fname = tmp_vsimem / "input.tif" + + nx = 1 + ny = 1 + + with gdal.GetDriverByName("GTiff").Create( + input_fname, nx, ny, 1, eType=gdal.GDT_Int8 + ) as input_ds: + input_ds.GetRasterBand(1).Fill(1) + gt = input_ds.GetGeoTransform() + + vrt_xml = f""" + + {', '.join([str(x) for x in gt])} + + Python + identity + + + + {input_fname} + 1 + + + + """ + + with gdal.config_option("GDAL_VRT_ENABLE_PYTHON", "YES"): + with gdal.Open(vrt_xml) as vrt_ds: + vrt_ds.ReadRaster() # materialize VRT + assert vrt_ds.GetRasterBand(1).DataType == dtype + + ############################################################################### # Cleanup. diff --git a/frmts/vrt/vrtderivedrasterband.cpp b/frmts/vrt/vrtderivedrasterband.cpp index bfc3d3aca48a..ec0e2606e0a1 100644 --- a/frmts/vrt/vrtderivedrasterband.cpp +++ b/frmts/vrt/vrtderivedrasterband.cpp @@ -88,6 +88,9 @@ static PyObject *GDALCreateNumpyArray(PyObject *pCreateArray, void *pBuffer, case GDT_Byte: pszDataType = "uint8"; break; + case GDT_Int8: + pszDataType = "int8"; + break; case GDT_UInt16: pszDataType = "uint16"; break; @@ -100,6 +103,12 @@ static PyObject *GDALCreateNumpyArray(PyObject *pCreateArray, void *pBuffer, case GDT_Int32: pszDataType = "int32"; break; + case GDT_Int64: + pszDataType = "int64"; + break; + case GDT_UInt64: + pszDataType = "uint64"; + break; case GDT_Float32: pszDataType = "float32"; break;