From 8a1380b03555e30448d0b802eaba7df4a70f33d0 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 30 Aug 2024 00:19:57 +0200 Subject: [PATCH 01/12] add Int8 --- raster/r.external/link.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/raster/r.external/link.c b/raster/r.external/link.c index 4ff0799fe69..7dda6a29b14 100644 --- a/raster/r.external/link.c +++ b/raster/r.external/link.c @@ -5,6 +5,10 @@ #include "proto.h" +#ifndef GDT_Int8 +#define GDT_Int8 14 +#endif + void query_band(GDALRasterBandH hBand, const char *output, struct Cell_head *cellhd, struct band_info *info) { @@ -30,6 +34,11 @@ void query_band(GDALRasterBandH hBand, const char *output, cellhd->format = 0; break; + case GDT_Int8: + info->data_type = CELL_TYPE; + cellhd->format = 1; + break; + case GDT_Int16: case GDT_UInt16: info->data_type = CELL_TYPE; From c79799eadb1676e98b6afeaa034a3c57c6461f96 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 30 Aug 2024 00:22:45 +0200 Subject: [PATCH 02/12] add Int8 --- lib/raster/gdal.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/raster/gdal.c b/lib/raster/gdal.c index a3bfce1b3b8..48be088f946 100644 --- a/lib/raster/gdal.c +++ b/lib/raster/gdal.c @@ -31,6 +31,10 @@ #include #endif +#ifndef GDT_Int8 +#define GDT_Int8 14 +#endif + /*! \brief Initialization @@ -125,6 +129,7 @@ struct GDAL_link *Rast_get_gdal_link(const char *name, const char *mapset) switch (type) { case GDT_Byte: + case GDT_Int8: case GDT_Int16: case GDT_UInt16: case GDT_Int32: From b0d9c6fff9ae3b62bca519b54ef0582241d42add Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 30 Aug 2024 00:23:06 +0200 Subject: [PATCH 03/12] add Int8 --- lib/raster/get_row.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/raster/get_row.c b/lib/raster/get_row.c index 1f08a1203f3..aa35c9b1894 100644 --- a/lib/raster/get_row.c +++ b/lib/raster/get_row.c @@ -22,6 +22,10 @@ #include "R.h" +#ifndef GDT_Int8 +#define GDT_Int8 14 +#endif + static void embed_nulls(int, void *, int, RASTER_MAP_TYPE, int, int); static int compute_window_row(int fd, int row, int *cellRow) @@ -368,6 +372,9 @@ static void gdal_values_int(int fd, const unsigned char *data, case GDT_Byte: c[i] = *(GByte *)d; break; + case GDT_Int8: + c[i] = *(GInt16 *)d; + break; case GDT_Int16: c[i] = *(GInt16 *)d; break; From 5f431691fcd2f8d1b6c349855bdbc4e605e69f25 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 30 Aug 2024 20:51:38 +0200 Subject: [PATCH 04/12] if gdalversion --- lib/raster/gdal.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/raster/gdal.c b/lib/raster/gdal.c index 48be088f946..7fa85a9836c 100644 --- a/lib/raster/gdal.c +++ b/lib/raster/gdal.c @@ -31,10 +31,6 @@ #include #endif -#ifndef GDT_Int8 -#define GDT_Int8 14 -#endif - /*! \brief Initialization @@ -129,7 +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: From bc9f6a89890e882a19d8a0e35fb92346d8183c78 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 30 Aug 2024 20:52:48 +0200 Subject: [PATCH 05/12] if gdalversion --- lib/raster/get_row.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/raster/get_row.c b/lib/raster/get_row.c index aa35c9b1894..05b34f30779 100644 --- a/lib/raster/get_row.c +++ b/lib/raster/get_row.c @@ -22,10 +22,6 @@ #include "R.h" -#ifndef GDT_Int8 -#define GDT_Int8 14 -#endif - static void embed_nulls(int, void *, int, RASTER_MAP_TYPE, int, int); static int compute_window_row(int fd, int row, int *cellRow) @@ -372,9 +368,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] = *(GInt16 *)d; + c[i] = *(signed char *)d; break; +#endif case GDT_Int16: c[i] = *(GInt16 *)d; break; From 890953b688f1ad73d6199b4c211200f1fb501d2f Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 30 Aug 2024 20:53:47 +0200 Subject: [PATCH 06/12] if gdalversion --- raster/r.external/link.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/raster/r.external/link.c b/raster/r.external/link.c index 7dda6a29b14..bde45546fc2 100644 --- a/raster/r.external/link.c +++ b/raster/r.external/link.c @@ -5,10 +5,6 @@ #include "proto.h" -#ifndef GDT_Int8 -#define GDT_Int8 14 -#endif - void query_band(GDALRasterBandH hBand, const char *output, struct Cell_head *cellhd, struct band_info *info) { @@ -34,10 +30,13 @@ 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: From 1565b1de59640450ca4177adaac2f15eff550fe1 Mon Sep 17 00:00:00 2001 From: Stefan Blumentrath Date: Sat, 31 Aug 2024 15:51:12 +0200 Subject: [PATCH 07/12] Update get_row.c --- lib/raster/get_row.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raster/get_row.c b/lib/raster/get_row.c index 05b34f30779..572d13c21fb 100644 --- a/lib/raster/get_row.c +++ b/lib/raster/get_row.c @@ -371,7 +371,7 @@ static void gdal_values_int(int fd, const unsigned char *data, /* GDT_Int8 was introduced in GDAL 3.7 */ #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3, 7, 0) case GDT_Int8: - c[i] = *(signed char *)d; + c[i] = *(int8_t *)d; break; #endif case GDT_Int16: From bcb0ecb986c3a51ffbbbb57c440f388d1c323cf3 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sat, 31 Aug 2024 07:00:14 +0200 Subject: [PATCH 08/12] add int8 test data --- raster/r.in.gdal/testsuite/data/int8.tif | Bin 0 -> 948 bytes raster/r.in.gdal/testsuite/data/int8.vrt | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 raster/r.in.gdal/testsuite/data/int8.tif create mode 100644 raster/r.in.gdal/testsuite/data/int8.vrt 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 0000000000000000000000000000000000000000..84f3e88ce634cb0a89c706b8eac1e79fa3e486e4 GIT binary patch literal 948 zcmebD)MDUZU|`^9U|?isU<9%xfS3`9%>-qGR53%@Aa!g=Y(YjAu-+1&gea1@7?ce% zQyi+sfr)`Z21!jYlnoSS;A`e#UFAD1}z}l z3*-nm_+SrV!f3bz0fvPGOaUX<2kZ4$q literal 0 HcmV?d00001 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 + + + + + + From b9db8cb860d6f74badd8c18f96bcde56b6bb2df9 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sat, 31 Aug 2024 07:00:58 +0200 Subject: [PATCH 09/12] add int8 test --- raster/r.in.gdal/testsuite/test_r_in_gdal.py | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) 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..c4c73ab4314 100644 --- a/raster/r.in.gdal/testsuite/test_r_in_gdal.py +++ b/raster/r.in.gdal/testsuite/test_r_in_gdal.py @@ -306,6 +306,32 @@ def test_netCDF_3d_5(self): self.assertLooksLike(map_list, text_from_file) + 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): From 28e1560ce9ca8eceb45f447476c5b72f69f8554e Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sat, 31 Aug 2024 07:02:39 +0200 Subject: [PATCH 10/12] import stdint.h --- lib/raster/get_row.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/raster/get_row.c b/lib/raster/get_row.c index 572d13c21fb..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 From 96c14854b2482271deffeba6f8d68ad1712ed79c Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 1 Sep 2024 17:09:24 +0200 Subject: [PATCH 11/12] skip test for GDAL < 3.7 --- raster/r.in.gdal/testsuite/test_r_in_gdal.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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 c4c73ab4314..aaf1f6a0ad2 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 + +import osgeo + from grass.gunittest.case import TestCase @@ -306,6 +310,10 @@ def test_netCDF_3d_5(self): self.assertLooksLike(map_list, text_from_file) + @unittest.skipIf( + osgeo.gdal_version[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""" From 2babe10e0489a0bd6167131579fb6c9ec005bfe4 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Mon, 2 Sep 2024 07:39:24 +0200 Subject: [PATCH 12/12] skip Int8 test for GDAL < 3.7 --- raster/r.in.gdal/testsuite/test_r_in_gdal.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 aaf1f6a0ad2..355e9b74eda 100644 --- a/raster/r.in.gdal/testsuite/test_r_in_gdal.py +++ b/raster/r.in.gdal/testsuite/test_r_in_gdal.py @@ -5,7 +5,7 @@ import unittest -import osgeo +from subprocess import check_output from grass.gunittest.case import TestCase @@ -311,7 +311,15 @@ def test_netCDF_3d_5(self): self.assertLooksLike(map_list, text_from_file) @unittest.skipIf( - osgeo.gdal_version[0:2] < (3, 7), + 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):