diff --git a/lib/raster/gdal.c b/lib/raster/gdal.c index a3bfce1b3b8..7fa85a9836c 100644 --- a/lib/raster/gdal.c +++ b/lib/raster/gdal.c @@ -125,6 +125,10 @@ struct GDAL_link *Rast_get_gdal_link(const char *name, const char *mapset) switch (type) { case GDT_Byte: +/* GDT_Int8 was introduced in GDAL 3.7 */ +#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3, 7, 0) + case GDT_Int8: +#endif case GDT_Int16: case GDT_UInt16: case GDT_Int32: diff --git a/lib/raster/get_row.c b/lib/raster/get_row.c index 1f08a1203f3..d95eadc6e2f 100644 --- a/lib/raster/get_row.c +++ b/lib/raster/get_row.c @@ -11,6 +11,7 @@ \author Original author CERL */ +#include #include #include #include @@ -368,6 +369,12 @@ static void gdal_values_int(int fd, const unsigned char *data, case GDT_Byte: c[i] = *(GByte *)d; break; +/* GDT_Int8 was introduced in GDAL 3.7 */ +#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3, 7, 0) + case GDT_Int8: + c[i] = *(int8_t *)d; + break; +#endif case GDT_Int16: c[i] = *(GInt16 *)d; break; diff --git a/raster/r.external/link.c b/raster/r.external/link.c index 4ff0799fe69..bde45546fc2 100644 --- a/raster/r.external/link.c +++ b/raster/r.external/link.c @@ -30,6 +30,14 @@ void query_band(GDALRasterBandH hBand, const char *output, cellhd->format = 0; break; +/* GDT_Int8 was introduced in GDAL 3.7 */ +#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3, 7, 0) + case GDT_Int8: + info->data_type = CELL_TYPE; + cellhd->format = 1; + break; +#endif + case GDT_Int16: case GDT_UInt16: info->data_type = CELL_TYPE; diff --git a/raster/r.in.gdal/testsuite/data/int8.tif b/raster/r.in.gdal/testsuite/data/int8.tif new file mode 100644 index 00000000000..84f3e88ce63 Binary files /dev/null and b/raster/r.in.gdal/testsuite/data/int8.tif differ diff --git a/raster/r.in.gdal/testsuite/data/int8.vrt b/raster/r.in.gdal/testsuite/data/int8.vrt new file mode 100644 index 00000000000..5a0b5ebe836 --- /dev/null +++ b/raster/r.in.gdal/testsuite/data/int8.vrt @@ -0,0 +1,20 @@ + + PROJCS["NAD83(HARN) / North Carolina",GEOGCS["NAD83(HARN)",DATUM["NAD83_High_Accuracy_Reference_Network",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6152"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4152"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",33.75],PARAMETER["central_meridian",-79],PARAMETER["standard_parallel_1",36.1666666666667],PARAMETER["standard_parallel_2",34.3333333333333],PARAMETER["false_easting",609601.22],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","3358"]] + 0.0000000000000000e+00, 1.0000000000000000e+00, 0.0000000000000000e+00, 2.4000000000000000e+01, 0.0000000000000000e+00, -1.0000000000000000e+00 + + Area + + + BAND + + + Gray + + ./int8.tif + 1 + + + + + + diff --git a/raster/r.in.gdal/testsuite/test_r_in_gdal.py b/raster/r.in.gdal/testsuite/test_r_in_gdal.py index 2b8bee0982a..355e9b74eda 100644 --- a/raster/r.in.gdal/testsuite/test_r_in_gdal.py +++ b/raster/r.in.gdal/testsuite/test_r_in_gdal.py @@ -3,6 +3,10 @@ @author Soeren Gebbert """ +import unittest + +from subprocess import check_output + from grass.gunittest.case import TestCase @@ -306,6 +310,44 @@ def test_netCDF_3d_5(self): self.assertLooksLike(map_list, text_from_file) + @unittest.skipIf( + tuple( + map( + int, + check_output(["gdal-config", "--version"]) + .decode("UTF8") + .split(".")[0:2], + ) + ) + < (3, 7), + "GDAL version too old. Int8 support was introduced in GDAL 3.7", + ) + def test_int8_data(self): + """Test that Int8 VRTs are imported""" + + self.assertModule( + "r.in.gdal", + input="data/int8.vrt", + output="test_gdal_import_map", + ) + + # Output of r.info + info_string = """north=24 + south=0 + east=24 + west=0 + nsres=1 + ewres=1 + rows=24 + cols=24 + cells=576 + datatype=CELL + ncats=0""" + + self.assertRasterFitsInfo( + raster="test_gdal_import_map", reference=info_string, precision=3 + ) + class TestGdalImportFails(TestCase): def test_error_handling_1(self):