From 9c8def4b659b6fdcd23a3c0185099e5a3635e6d6 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Thu, 24 May 2012 23:13:25 +0000 Subject: [PATCH] Code cleanup related to rt_band_load_offline_data() git-svn-id: http://svn.osgeo.org/postgis/trunk@9819 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_api.c | 60 +++++++++++++++++--------------------- raster/test/core/testapi.c | 8 +++++ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 6cf1392f8..f6570d3e1 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -1522,7 +1522,8 @@ rt_band_load_offline_data(rt_band band) { _rast = rt_raster_from_gdal_dataset(hdsDst); GDALClose(hdsDst); - GDALClose(hdsSrc); + /* XXX: need to find a way to clean up the GDALOpenShared datasets at end of transaction */ + /* GDALClose(hdsSrc); */ if (_rast == NULL) { rterror("rt_band_load_offline_data: Cannot load data from offline raster: %s", band->data.offline.path); @@ -2466,45 +2467,38 @@ rt_band_get_min_value(rt_band band) { int -rt_band_check_is_nodata(rt_band band) -{ - int i, j; - double pxValue = band->nodataval; - +rt_band_check_is_nodata(rt_band band) { + int i, j, err; + double pxValue; + assert(NULL != band); - assert(NULL != band); + /* Check if band has nodata value */ + if (!band->hasnodata) { + RASTER_DEBUG(3, "Band has no NODATA value"); + band->isnodata = FALSE; + return FALSE; + } - /* Check if band has nodata value */ - if (!band->hasnodata) - { - RASTER_DEBUG(3, "Unknown nodata value for band"); - band->isnodata = FALSE; - return FALSE; - } + pxValue = band->nodataval; - if (band->offline && band->data.offline.mem == NULL) { - if (rt_band_load_offline_data(band)) { - rterror("rt_band_check_is_nodata: Cannot load offline band's data"); + /* Check all pixels */ + for (i = 0; i < band->width; i++) { + for (j = 0; j < band->height; j++) { + err = rt_band_get_pixel(band, i, j, &pxValue); + if (err != 0) { + rterror("rt_band_check_is_nodata: Cannot get band pixel"); return FALSE; } - } - - /* Check all pixels */ - for(i = 0; i < band->width; i++) - { - for(j = 0; j < band->height; j++) - { - rt_band_get_pixel(band, i, j, &pxValue); - if (FLT_NEQ(pxValue, band->nodataval)) { - band->isnodata = FALSE; - return FALSE; - } - } - } + else if (FLT_NEQ(pxValue, band->nodataval)) { + band->isnodata = FALSE; + return FALSE; + } + } + } - band->isnodata = TRUE; - return TRUE; + band->isnodata = TRUE; + return TRUE; } /** diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index 492e085de..ca486930b 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -1596,6 +1596,9 @@ static void testRasterToGDAL() { } } + /* add check that band isn't NODATA */ + CHECK((rt_band_check_is_nodata(band) == FALSE)); + gdal = rt_raster_to_gdal(raster, srs, "PNG", NULL, &gdalSize); /*printf("gdalSize: %d\n", (int) gdalSize);*/ CHECK(gdalSize); @@ -2559,6 +2562,11 @@ static void testLoadOfflineBand() { } } + /* test rt_band_check_is_nodata */ + rtdealloc(band->data.offline.mem); + band->data.offline.mem = NULL; + CHECK((rt_band_check_is_nodata(band) == FALSE)); + deepRelease(rast); } -- 2.40.0