From: Bborie Park Date: Tue, 3 Jul 2012 23:40:40 +0000 (+0000) Subject: Fixed handling of pixel value check for NODATA X-Git-Tag: 2.1.0beta2~823 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59951e21bee6587a61a921600b31cd85c86cfaea;p=postgis Fixed handling of pixel value check for NODATA git-svn-id: http://svn.osgeo.org/postgis/trunk@10028 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 65a96b14b..ebc39bbf8 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -2325,6 +2325,10 @@ int rt_band_get_nearest_pixel( } } + /* no NODATA, exclude is FALSE */ + if (!band->hasnodata) + exclude_nodata_value = FALSE; + /* determine the maximum distance to prevent an infinite loop */ if (!distance) { int a, b; @@ -2502,6 +2506,9 @@ rt_band_get_pixel_of_value( assert(NULL != band); assert(NULL != pixels); + if (!band->hasnodata) + exclude_nodata_value = FALSE; + for (x = 0; x < band->width; x++) { for (y = 0; y < band->height; y++) { err = rt_band_get_pixel(band, x, y, &pixval); @@ -5706,7 +5713,10 @@ rt_raster_gdal_polygonize( if (exclude_nodata_value) { iBandHasNodataValue = rt_band_get_hasnodata_flag(band); - if (iBandHasNodataValue) dBandNoData = rt_band_get_nodata(band); + if (iBandHasNodataValue) + dBandNoData = rt_band_get_nodata(band); + else + exclude_nodata_value = FALSE; } /***************************************************** diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 9cac44dbd..a8f6c386a 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -2557,8 +2557,12 @@ Datum RASTER_getPixelPolygons(PG_FUNCTION_ARGS) } hasnodata = rt_band_get_hasnodata_flag(band); - if (hasnodata) + if (hasnodata) { nodataval = rt_band_get_nodata(band); + POSTGIS_RT_DEBUGF(4, "(hasnodata, nodataval) = (%d, %f)", hasnodata, nodataval); + } + else + exclude_nodata_value = FALSE; } while (0); } @@ -2613,8 +2617,10 @@ Datum RASTER_getPixelPolygons(PG_FUNCTION_ARGS) SRF_RETURN_DONE(funcctx); } pix[pixcount].geom = (LWGEOM *) poly; + /* POSTGIS_RT_DEBUGF(4, "poly @ %p", poly); POSTGIS_RT_DEBUGF(4, "geom @ %p", pix[pixcount].geom); + */ /* x, y */ pix[pixcount].x = x; @@ -2638,7 +2644,8 @@ Datum RASTER_getPixelPolygons(PG_FUNCTION_ARGS) } if ( - !exclude_nodata_value || ( + !exclude_nodata_value || + !hasnodata || ( exclude_nodata_value && (hasnodata != FALSE) && ( FLT_NEQ(pix[pixcount].value, nodataval) && @@ -2648,11 +2655,13 @@ Datum RASTER_getPixelPolygons(PG_FUNCTION_ARGS) ) { pix[pixcount].nodata = 0; } - else + else { pix[pixcount].nodata = 1; + } } - else + else { pix[pixcount].nodata = 1; + } pixcount++; } @@ -3089,7 +3098,8 @@ Datum RASTER_nearestValue(PG_FUNCTION_ARGS) /* value at point, return value */ if ( - !exclude_nodata_value || ( + !exclude_nodata_value || + !rt_band_get_hasnodata_flag(band) || ( exclude_nodata_value && rt_band_get_hasnodata_flag(band) && ( FLT_NEQ(value, rt_band_get_nodata(band)) && @@ -3324,7 +3334,8 @@ Datum RASTER_neighborhood(PG_FUNCTION_ARGS) /* add pixel to neighborhood */ if ( - !exclude_nodata_value || ( + !exclude_nodata_value || + !rt_band_get_hasnodata_flag(band) || ( exclude_nodata_value && (rt_band_get_hasnodata_flag(band) != FALSE) && ( FLT_NEQ(pixval, rt_band_get_nodata(band)) &&