]> granicus.if.org Git - postgis/commitdiff
Added shortcut mechanism for copying data in rt_raster_from_gdal_dataset() when the...
authorBborie Park <bkpark at ucdavis.edu>
Thu, 5 Jan 2012 21:18:56 +0000 (21:18 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 5 Jan 2012 21:18:56 +0000 (21:18 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8684 b70326c6-7e19-0410-871a-916f4a2858ee

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

index a12a688fc9269d8e438ffdf92027282085976c26..2e1a2d73b1393a7e61dcdc2bf3ae425d0f4ad314 100644 (file)
@@ -7032,14 +7032,24 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) {
                                        return NULL;
                                }
 
-                               ptr = values;
-                               for (iY = 0; iY < nYValid; iY++) {
+                               /* if block width is same as raster width, shortcut */
+                               if (nXBlocks == 1 && nYBlockSize > 1 && nXValid == width) {
+                                       x = 0;
+                                       y = nYBlockSize * iYBlock;
+
+                                       RASTER_DEBUGF(4, "Setting set of pixel lines at (%d, %d) for %d pixels", x, y, nXValid * nYValid);
+                                       rt_band_set_pixel_line(band, x, y, values, nXValid * nYValid);
+                               }
+                               else {
+                                       ptr = values;
                                        x = nXBlockSize * iXBlock;
-                                       y = iY + (nYBlockSize * iYBlock);
+                                       for (iY = 0; iY < nYValid; iY++) {
+                                               y = iY + (nYBlockSize * iYBlock);
 
-                                       RASTER_DEBUGF(4, "Setting pixel line at (%d, %d) for %d pixels", x, y, nXValid);
-                                       rt_band_set_pixel_line(band, x, y, ptr, nXValid);
-                                       ptr += (nXValid * ptlen);
+                                               RASTER_DEBUGF(4, "Setting pixel line at (%d, %d) for %d pixels", x, y, nXValid);
+                                               rt_band_set_pixel_line(band, x, y, ptr, nXValid);
+                                               ptr += (nXValid * ptlen);
+                                       }
                                }
                        }
                }
index fd52280470fec6bdfab5fb30244fa511019b7b75..56a6e61f8cba7220e56ab3ede94e77a6a4d6751a 100644 (file)
@@ -1430,10 +1430,11 @@ static void testGDALToRaster() {
        rt_raster raster;
        rt_raster rast;
        rt_band band;
+       const uint32_t xmax = 100;
+       const uint32_t ymax = 100;
        uint32_t x;
-       uint32_t xmax = 100;
        uint32_t y;
-       uint32_t ymax = 100;
+       double values[xmax][ymax];
        int rtn = 0;
        double value;
 
@@ -1448,7 +1449,8 @@ static void testGDALToRaster() {
 
        for (x = 0; x < xmax; x++) {
                for (y = 0; y < ymax; y++) {
-                       rtn = rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1));
+                       values[x][y] = (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1);
+                       rtn = rt_band_set_pixel(band, x, y, values[x][y]);
                        CHECK((rtn != -1));
                }
        }
@@ -1466,17 +1468,13 @@ static void testGDALToRaster() {
        band = rt_raster_get_band(rast, 0);
        CHECK(band);
 
-       rtn = rt_band_get_pixel(band, 0, 3, &value);
-       CHECK((rtn != -1));
-       CHECK(FLT_EQ(value, 0.75));
-
-       rtn = rt_band_get_pixel(band, 99, 0, &value);
-       CHECK((rtn != -1));
-       CHECK(FLT_EQ(value, 1.98));
-
-       rtn = rt_band_get_pixel(band, 95, 4, &value);
-       CHECK((rtn != -1));
-       CHECK(FLT_EQ(value, 9.54));
+       for (x = 0; x < xmax; x++) {
+               for (y = 0; y < ymax; y++) {
+                       rtn = rt_band_get_pixel(band, x, y, &value);
+                       CHECK((rtn != -1));
+                       CHECK(FLT_EQ(value, values[x][y]));
+               }
+       }
 
        GDALClose(gdds);
        GDALDeregisterDriver(gddrv);