]> granicus.if.org Git - postgis/commitdiff
Code cleanup related to rt_band_load_offline_data()
authorBborie Park <bkpark at ucdavis.edu>
Thu, 24 May 2012 23:13:25 +0000 (23:13 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 24 May 2012 23:13:25 +0000 (23:13 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9819 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/test/core/testapi.c

index 6cf1392f88d237de67da9f58a3e618c1ad7e6cb2..f6570d3e14e93afaddd40b0b2aa6ec95ab2b0894 100644 (file)
@@ -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;
 }
 
 /**
index 492e085de55ddf49a077fd8a615f631ce4477870..ca486930b67ac34f634cf095d4f3984c6e5d76bf 100644 (file)
@@ -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);
 }