[SCM] PostGIS branch master updated. 3.6.0rc2-496-gf09adbed3
git at osgeo.org
git at osgeo.org
Thu Jun 4 12:18:13 PDT 2026
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 f09adbed379aad9ed9374cd19ca7ec3b6c2c0b49 (commit)
from c9bdc50fbdaac675ef784463df1849e27d447872 (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 f09adbed379aad9ed9374cd19ca7ec3b6c2c0b49
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Thu Jun 4 12:17:19 2026 -0700
Use nodata mask rather than a SQL filter in ST_Polygon
Avoids polygonizing nodata areas with ST_Polygon, matches
old behaviour pre-3.x (2018).
Closes #6010
diff --git a/raster/rt_core/rt_geometry.c b/raster/rt_core/rt_geometry.c
index 2c126f4b8..70d815c69 100644
--- a/raster/rt_core/rt_geometry.c
+++ b/raster/rt_core/rt_geometry.c
@@ -979,7 +979,6 @@ rt_raster_gdal_polygonize(
int *pnElements
) {
CPLErr cplerr = CE_None;
- char *pszQuery;
long j;
OGRSFDriverH ogr_drv = NULL;
GDALDriverH gdal_drv = NULL;
@@ -1140,9 +1139,14 @@ rt_raster_gdal_polygonize(
/*
* Why: We pass the shared interrupt-aware progress callback so GDAL can
* unwind promptly when PostgreSQL requests cancellation (#4222).
+ * Use the band's nodata mask so large/infinite nodata values are excluded
+ * before polygonizing, bypassing the broken %f string-format filter (#6010).
*/
+ GDALRasterBandH mask_band = iBandHasNodataValue
+ ? GDALGetMaskBand(gdal_band)
+ : NULL;
cplerr = GDALFPolygonize(
- gdal_band, NULL, hLayer, iPixVal, NULL, rt_util_gdal_progress_func, (void *)"GDALFPolygonize");
+ gdal_band, mask_band, hLayer, iPixVal, NULL, rt_util_gdal_progress_func, (void *)"GDALFPolygonize");
if (cplerr != CE_None) {
rterror("rt_raster_gdal_polygonize: Could not polygonize GDAL band");
@@ -1156,25 +1160,6 @@ rt_raster_gdal_polygonize(
return NULL;
}
- /**
- * Optimization: Apply a OGR SQL filter to the layer to select the
- * features different from NODATA value.
- *
- * Thanks to David Zwarg.
- **/
- if (iBandHasNodataValue) {
- size_t sz = 50 * sizeof (char);
- pszQuery = (char *) rtalloc(sz);
- snprintf(pszQuery, sz, "PixelValue != %f", dBandNoData );
- OGRErr e = OGR_L_SetAttributeFilter(hLayer, pszQuery);
- if (e != OGRERR_NONE) {
- rtwarn("Error filtering NODATA values for band. All values will be treated as data values");
- }
- }
- else {
- pszQuery = NULL;
- }
-
/*********************************************************************
* Transform OGR layers to WKB polygons
* XXX jorgearevalo: GDALPolygonize does not set the coordinate system
@@ -1193,8 +1178,6 @@ rt_raster_gdal_polygonize(
if (destroy_gdal_drv) GDALDestroyDriver(gdal_drv);
OGR_Fld_Destroy(hFldDfn);
OGR_DS_DeleteLayer(memdatasource, 0);
- if (NULL != pszQuery)
- rtdealloc(pszQuery);
OGRReleaseDataSource(memdatasource);
return NULL;
@@ -1225,8 +1208,6 @@ rt_raster_gdal_polygonize(
if (destroy_gdal_drv) GDALDestroyDriver(gdal_drv);
OGR_Fld_Destroy(hFldDfn);
OGR_DS_DeleteLayer(memdatasource, 0);
- if (NULL != pszQuery)
- rtdealloc(pszQuery);
OGRReleaseDataSource(memdatasource);
return NULL;
@@ -1291,7 +1272,6 @@ rt_raster_gdal_polygonize(
RASTER_DEBUG(3, "destroying OGR MEM vector");
OGR_Fld_Destroy(hFldDfn);
OGR_DS_DeleteLayer(memdatasource, 0);
- if (NULL != pszQuery) rtdealloc(pszQuery);
OGRReleaseDataSource(memdatasource);
return pols;
diff --git a/raster/test/cunit/cu_gdal.c b/raster/test/cunit/cu_gdal.c
index 18b1b6314..67fdaf55c 100644
--- a/raster/test/cunit/cu_gdal.c
+++ b/raster/test/cunit/cu_gdal.c
@@ -190,7 +190,8 @@ static void test_gdal_polygonize(void) {
nPols = 0;
gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
- CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
+ /* nodata=1.8 pixels are excluded: only 0.0 (x2 regions) and 2.8 remain */
+ CU_ASSERT_DOUBLE_EQUAL(nPols, 3, FLT_EPSILON);
total_area = 0; total_val = 0;
for (i = 0; i < nPols; i++) {
total_val += gv[i].val;
@@ -199,8 +200,8 @@ static void test_gdal_polygonize(void) {
lwgeom_free((LWGEOM *) gv[i].geom);
}
printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
- CU_ASSERT_DOUBLE_EQUAL(total_val, 4.6, FLT_EPSILON);
- CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
+ CU_ASSERT_DOUBLE_EQUAL(total_val, 2.8, FLT_EPSILON);
+ CU_ASSERT_DOUBLE_EQUAL(total_area, 65, FLT_EPSILON);
rtdealloc(gv);
@@ -214,7 +215,8 @@ static void test_gdal_polygonize(void) {
nPols = 0;
gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
- CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
+ /* nodata=2.8 pixels are excluded: only 0.0 (x2 regions) and 1.8 remain */
+ CU_ASSERT_DOUBLE_EQUAL(nPols, 3, FLT_EPSILON);
total_area = 0; total_val = 0;
for (i = 0; i < nPols; i++) {
total_val += gv[i].val;
@@ -224,8 +226,8 @@ static void test_gdal_polygonize(void) {
}
printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
- CU_ASSERT_DOUBLE_EQUAL(total_val, 4.6, FLT_EPSILON);
- CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
+ CU_ASSERT_DOUBLE_EQUAL(total_val, 1.8, FLT_EPSILON);
+ CU_ASSERT_DOUBLE_EQUAL(total_area, 69, FLT_EPSILON);
rtdealloc(gv);
cu_free_raster(rt);
diff --git a/raster/test/regress/rt_polygon.sql b/raster/test/regress/rt_polygon.sql
index 111f089fa..ea1e3461d 100644
--- a/raster/test/regress/rt_polygon.sql
+++ b/raster/test/regress/rt_polygon.sql
@@ -151,3 +151,17 @@ FROM (
DROP FUNCTION temp_geos_version();
DROP TABLE IF EXISTS raster_polygon;
+
+-- #6010: nodata=FLT_MAX (32BF): only the 8 valid pixels should polygonize, not the nodata center pixel
+SELECT count(*) = 1 FROM ST_DumpAsPolygons(
+ ST_SetValue(
+ ST_AddBand(ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
+ 1, '32BF'::text, -9.0, 3.4028234663852886e+38),
+ 1, 2, 2, 3.4028234663852886e+38));
+
+-- #6010: nodata=DBL_MAX (64BF): only the 8 valid pixels should polygonize, not the nodata center pixel
+SELECT count(*) = 1 FROM ST_DumpAsPolygons(
+ ST_SetValue(
+ ST_AddBand(ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
+ 1, '64BF'::text, -9.0, 1.7976931348623157e+308),
+ 1, 2, 2, 1.7976931348623157e+308));
diff --git a/raster/test/regress/rt_polygon_expected b/raster/test/regress/rt_polygon_expected
index 3d2628a5e..22ec3b719 100644
--- a/raster/test/regress/rt_polygon_expected
+++ b/raster/test/regress/rt_polygon_expected
@@ -5,3 +5,5 @@ t
t
t
t
+t
+t
-----------------------------------------------------------------------
Summary of changes:
raster/rt_core/rt_geometry.c | 32 ++++++--------------------------
raster/test/cunit/cu_gdal.c | 14 ++++++++------
raster/test/regress/rt_polygon.sql | 14 ++++++++++++++
raster/test/regress/rt_polygon_expected | 2 ++
4 files changed, 30 insertions(+), 32 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list