[SCM] PostGIS branch master updated. 3.5.0-270-g614eca7c1
git at osgeo.org
git at osgeo.org
Tue Apr 15 10:37:24 PDT 2025
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".
The branch, master has been updated
via 614eca7c169cd6e9819801d3ea99d5258262c58b (commit)
from 0a8765ba91e3289390c34906214d0b0cb21c48de (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 614eca7c169cd6e9819801d3ea99d5258262c58b
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Tue Apr 15 10:36:58 2025 -0700
Remove unnecessary raster-level check for a nodata value
on the src, since the dst will always need a nodata value
in order to infill the gaps created by the raster warping
process. In general at least, and doing it in specific
(only for warps that create empty cells) would be way too
complex.
References #5881
diff --git a/raster/rt_core/rt_warp.c b/raster/rt_core/rt_warp.c
index 73beef1f7..59110feec 100644
--- a/raster/rt_core/rt_warp.c
+++ b/raster/rt_core/rt_warp.c
@@ -29,7 +29,6 @@
*/
#include "../../postgis_config.h"
-/* #define POSTGIS_DEBUG_LEVEL 4 */
#include "librtcore.h"
#include "librtcore_internal.h"
@@ -189,8 +188,6 @@ rt_raster rt_raster_gdal_warp(
char *dst_options[] = {"SUBCLASS=VRTWarpedDataset", NULL};
_rti_warp_arg arg = NULL;
- int hasnodata = 0;
-
GDALRasterBandH band;
rt_band rtband = NULL;
rt_pixtype pt = PT_END;
@@ -819,7 +816,6 @@ rt_raster rt_raster_gdal_warp(
/* set nodata */
if (rt_band_get_hasnodata_flag(rtband) != FALSE) {
- hasnodata = 1;
rt_band_get_nodata(rtband, &nodata);
if (GDALSetRasterNoDataValue(band, nodata) != CE_None)
rtwarn("rt_raster_gdal_warp: Could not set nodata value for band %d", i);
@@ -869,6 +865,7 @@ rt_raster rt_raster_gdal_warp(
arg->wopts->pfnTransformer = arg->transform.func;
arg->wopts->pTransformerArg = arg->transform.arg.transform;
arg->wopts->papszWarpOptions = (char **) CPLMalloc(sizeof(char *) * 2);
+
arg->wopts->papszWarpOptions[0] = (char *) CPLMalloc(sizeof(char) * (strlen("INIT_DEST=NO_DATA") + 1));
strcpy(arg->wopts->papszWarpOptions[0], "INIT_DEST=NO_DATA");
arg->wopts->papszWarpOptions[1] = NULL;
@@ -880,8 +877,17 @@ rt_raster rt_raster_gdal_warp(
for (i = 0; i < arg->wopts->nBandCount; i++)
arg->wopts->panDstBands[i] = arg->wopts->panSrcBands[i] = i + 1;
- /* set nodata mapping */
- if (hasnodata) {
+ /*
+ * https://trac.osgeo.org/postgis/ticket/5881
+ * In order to call GDALWarp with BAND_INIT=NO_DATA we need to ensure
+ * that the src and dst rasters have nodata values and they are
+ * matched up nicely. This block used by tested with the hasnodata
+ * check on all src raster bands, but now we just do it every time
+ * because that makes sense (any warped raster is likely to have
+ * empty corners on output, and those corners need to be filled with
+ * some kind of NODATA value).
+ */
+ {
RASTER_DEBUG(3, "Setting nodata mapping");
arg->wopts->padfSrcNoDataReal = (double *) CPLMalloc(numBands * sizeof(double));
arg->wopts->padfDstNoDataReal = (double *) CPLMalloc(numBands * sizeof(double));
diff --git a/raster/test/cunit/cu_gdal.c b/raster/test/cunit/cu_gdal.c
index a0146e34c..1127b26ba 100644
--- a/raster/test/cunit/cu_gdal.c
+++ b/raster/test/cunit/cu_gdal.c
@@ -519,6 +519,71 @@ static void test_gdal_warp() {
cu_free_raster(raster);
}
+static void test_gdal_warp_preserves_data(void) {
+ const char *filename = "../regress/loader/Projected.tif";
+ GDALDatasetH hDS_in = NULL;
+ rt_raster rast_in = NULL;
+ rt_raster rast_out = NULL;
+ int band_count_in, band_count_out, i;
+
+ // double scale_x = 0.0, scale_y = 0.0;
+ // double dim_x = 0.0, dim_y = 0.0;
+ // int width = 0, height = 0;
+ // double grid_xw = 0.0, grid_yw = 0.0;
+ // double skew_x = 0.0, skew_y = 0.0;
+
+ double max_err = 0.125;
+ GDALResampleAlg alg = GRA_NearestNeighbour;
+
+ const char *src_srs = "EPSG:4326";
+ const char *dst_srs = "EPSG:3857";
+
+ /* Handle to TIFF */
+ GDALAllRegister();
+ hDS_in = GDALOpen(filename, GA_ReadOnly);
+ CU_ASSERT(hDS_in != NULL);
+
+ /* Read TIFF into memory as rt_raster */
+ rast_in = rt_raster_from_gdal_dataset(hDS_in);
+ CU_ASSERT(rast_in != NULL);
+
+ /* Warp raster using default options */
+ rast_out = rt_raster_gdal_warp(rast_in,
+ src_srs, dst_srs,
+ NULL, NULL, // &scale_x, &scale_y,
+ NULL, NULL, // &dim_x, &dim_y,
+ NULL, NULL, // &width, &height,
+ NULL, NULL, // &grid_xw, &grid_yw,
+ NULL, NULL, // &skew_x, &skew_y,
+ alg, max_err);
+ CU_ASSERT(rast_out != NULL);
+
+ band_count_in = rt_raster_get_num_bands(rast_in);
+ band_count_out = rt_raster_get_num_bands(rast_out);
+ CU_ASSERT_EQUAL(band_count_in, band_count_out);
+
+ for (i = 0; i < band_count_in; i++) {
+ double tolerance = 0.1;
+ rt_bandstats stats_in, stats_out;
+ rt_band band_in = rt_raster_get_band(rast_in, i);
+ rt_band band_out = rt_raster_get_band(rast_out, i);
+
+ CU_ASSERT(band_in != NULL);
+ CU_ASSERT(band_out != NULL);
+
+ stats_in = rt_band_get_summary_stats(band_in, 1, 1, 0, NULL, NULL, NULL);
+ stats_out = rt_band_get_summary_stats(band_out, 1, 1, 0, NULL, NULL, NULL);
+
+ CU_ASSERT_DOUBLE_EQUAL(stats_in->min, stats_out->min, fabs(stats_in->min) * tolerance);
+ CU_ASSERT_DOUBLE_EQUAL(stats_in->max, stats_out->max, fabs(stats_in->max) * tolerance);
+ CU_ASSERT_DOUBLE_EQUAL(stats_in->mean, stats_out->mean, fabs(stats_in->mean) * tolerance);
+ }
+
+ rt_raster_destroy(rast_in);
+ rt_raster_destroy(rast_out);
+ GDALClose(hDS_in);
+}
+
/* register tests */
void gdal_suite_setup(void);
void gdal_suite_setup(void)
@@ -531,5 +596,6 @@ void gdal_suite_setup(void)
PG_ADD_TEST(suite, test_raster_to_gdal);
PG_ADD_TEST(suite, test_gdal_to_raster);
PG_ADD_TEST(suite, test_gdal_warp);
+ PG_ADD_TEST(suite, test_gdal_warp_preserves_data);
}
-----------------------------------------------------------------------
Summary of changes:
raster/rt_core/rt_warp.c | 18 ++++++++-----
raster/test/cunit/cu_gdal.c | 66 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 6 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list