]> granicus.if.org Git - postgis/commitdiff
Refactored the GDALRasterIO part of rt_raster_from_gdal_dataset to use scanlines...
authorBborie Park <bkpark at ucdavis.edu>
Wed, 7 Dec 2011 15:29:46 +0000 (15:29 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 7 Dec 2011 15:29:46 +0000 (15:29 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8313 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_core/rt_api.h
raster/rt_pg/rt_pg.c

index fa6d4c6067697af6a51de140b58886902c7de4cb..59a9d48eedce380c5f2488c9d6a92dd74489e1fa 100644 (file)
@@ -33,8 +33,6 @@
 #include <stdarg.h> /* for va_list, va_start etc */
 #include <string.h> /* for memcpy and strlen */
 #include <assert.h>
-#include <float.h> /* for FLT_EPSILON and float type limits */
-#include <limits.h> /* for integer type limits */
 #include <time.h> /* for time */
 #include "rt_api.h"
 
@@ -6636,12 +6634,6 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) {
        int x;
        int y;
        double value;
-
-       int nXBlocks, nYBlocks;
-       int nXBlockSize, nYBlockSize;
-       int iXBlock, iYBlock;
-       int nXValid, nYValid;
-       int iY, iX;
        double *values = NULL;
 
        assert(NULL != ds);
@@ -6751,67 +6743,35 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) {
                }
                band = rt_raster_get_band(rast, idx);
 
-               /* this makes use of GDAL's "natural" blocks */
-               GDALGetBlockSize(gdband, &nXBlockSize, &nYBlockSize);
-               nXBlocks = (width + nXBlockSize - 1) / nXBlockSize;
-               nYBlocks = (height + nYBlockSize - 1) / nYBlockSize;
-               RASTER_DEBUGF(4, "(nXBlockSize, nYBlockSize) = (%d, %d)", nXBlockSize, nYBlockSize);
-               RASTER_DEBUGF(4, "(nXBlocks, nYBlocks) = (%d, %d)", nXBlocks, nYBlocks);
-
-               for (iYBlock = 0; iYBlock < nYBlocks; iYBlock++) { /* row */
-                       for (iXBlock = 0; iXBlock < nXBlocks; iXBlock++) { /* column */
-                               x = iXBlock * nXBlockSize;
-                               y = iYBlock * nYBlockSize;
-                               RASTER_DEBUGF(4, "(iXBlock, iYBlock) = (%d, %d)", iXBlock, iYBlock);
-                               RASTER_DEBUGF(4, "(x, y) = (%d, %d)", x, y);
-
-                               if ((iXBlock + 1) * nXBlockSize > width)
-                                       nXValid = width - (iXBlock * nXBlockSize);
-                               else
-                                       nXValid = nXBlockSize;
+               /* use rows */
+               values = rtalloc(sizeof(double) * width);
+               for (y = 0; y < height; y++) {
+                       cplerr = GDALRasterIO(
+                               gdband, GF_Read,
+                               0, y,
+                               width, 1,
+                               values, width, 1,
+                               GDT_Float64,
+                               0, 0
+                       );
+                       if (cplerr != CE_None) {
+                               rterror("rt_raster_from_gdal_dataset: Unable to get data from GDAL band");
+                               rtdealloc(values);
+                               rt_raster_destroy(rast);
+                               return NULL;
+                       }
 
-                               if ((iYBlock + 1) * nYBlockSize > height)
-                                       nYValid = height - (iYBlock * nYBlockSize);
-                               else
-                                       nYValid = nYBlockSize;
-
-                               values = rtalloc(nXValid * nYValid * sizeof(double));
-                               /* values is ordered from left to right, top to bottom */
-                               cplerr = GDALRasterIO(
-                                       gdband, GF_Read,
-                                       x, y,
-                                       nXValid, nYValid,
-                                       values, nXValid, nYValid,
-                                       GDT_Float64,
-                                       0, 0
-                               );
-                               if (cplerr != CE_None) {
-                                       rterror("rt_raster_from_gdal_dataset: Unable to get data from GDAL band");
+                       for (x = 0; x < width; x++) {
+                               value = values[x];
+                               if (rt_band_set_pixel(band, x, y, value) < 0) {
+                                       rterror("rt_raster_from_gdal_dataset: Unable to save data from GDAL band");
                                        rtdealloc(values);
                                        rt_raster_destroy(rast);
                                        return NULL;
                                }
-
-                               for (iY = 0; iY < nYValid; iY++) {
-                                       for (iX = 0; iX < nXValid; iX++) {
-                                               x = iX + (nXBlockSize * iXBlock);
-                                               y = iY + (nYBlockSize * iYBlock);
-                                               value = values[iX + iY * nXBlockSize];
-
-                                               RASTER_DEBUGF(5, "(x, y, value) = (%d, %d, %f)", x, y, value);
-
-                                               if (rt_band_set_pixel(band, x, y, value) < 0) {
-                                                       rterror("rt_raster_from_gdal_dataset: Unable to save data from GDAL band");
-                                                       rtdealloc(values);
-                                                       rt_raster_destroy(rast);
-                                                       return NULL;
-                                               }
-                                       }
-                               }
-
-                               rtdealloc(values);
                        }
                }
+               rtdealloc(values);
        }
 
        return rast;
index 82bce6c93014510a4e3280c2decd4ce21b0a9139..4dfe28ad907b0e183affa0a6402c040e70e27cea 100644 (file)
@@ -92,6 +92,8 @@
 
 #include <stdlib.h> /* For size_t, srand and rand */
 #include <stdint.h> /* For C99 int types */
+#include <float.h> /* for FLT_EPSILON and float type limits */
+#include <limits.h> /* for integer type limits */
 
 #include "lwgeom_geos.h"
 #include "liblwgeom.h"
index 712301a0dd68b5eca62e91c1a38efb5d39c6cbb6..88eb7e1f26cc6f7c689a7136b38c5b1a3d8eec03 100644 (file)
@@ -29,7 +29,6 @@
  */
 
 #include <math.h>
-#include <float.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h> /* for strtod in RASTER_reclass */