]> granicus.if.org Git - postgis/commitdiff
raster2pgsql no longer pads tiles by default based upon tile position and tile
authorBborie Park <bkpark at ucdavis.edu>
Fri, 14 Dec 2012 20:26:05 +0000 (20:26 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Fri, 14 Dec 2012 20:26:05 +0000 (20:26 +0000)
size. This is part of the refactoring to remove padded tiles. Flag -P
added so that users can indicate that tiles should be padded.
Ticket #826.

git-svn-id: http://svn.osgeo.org/postgis/trunk@10829 b70326c6-7e19-0410-871a-916f4a2858ee

raster/loader/raster2pgsql.c
raster/loader/raster2pgsql.h
raster/test/regress/Makefile.in
raster/test/regress/loader/Tiled8x8-post.pl [new file with mode: 0755]
raster/test/regress/loader/Tiled8x8-post.sh [new file with mode: 0755]
raster/test/regress/loader/Tiled8x8-pre.pl [new file with mode: 0755]
raster/test/regress/loader/Tiled8x8-pre.sh [new file with mode: 0755]
raster/test/regress/loader/Tiled8x8.opts [new file with mode: 0644]
raster/test/regress/loader/Tiled8x8.select.expected [new file with mode: 0644]
raster/test/regress/loader/Tiled8x8.select.sql [new file with mode: 0644]

index 599eb2eb27a749a393369f0ca84b5e7a2b7e0746..b218660e5480940be305b1912bf04e6975f6cd99 100644 (file)
@@ -350,6 +350,10 @@ usage() {
                "      an appropriate tile size using the first raster and applied to\n"
                "      all rasters.\n"
        ));
+       printf(_(
+               "  -P Pad right-most and bottom-most tiles to guarantee that all tiles\n"
+               "     have the same width and height.\n"
+       ));
        printf(_(
                "  -R  Register the raster as an out-of-db (filesystem) raster.  Provided\n"
                "      raster should have absolute path to the file\n"
@@ -689,6 +693,7 @@ init_config(RTLOADERCFG *config) {
        config->nband = NULL;
        config->nband_count = 0;
        memset(config->tile_size, 0, sizeof(int) * 2);
+       config->pad_tile = 0;
        config->outdb = 0;
        config->opt = 'c';
        config->idx = 0;
@@ -1288,6 +1293,7 @@ build_overview(int idx, RTLOADERCFG *config, RASTERINFO *info, int ovx, STRINGBU
        VRTDatasetH hdsDst;
        VRTSourcedRasterBandH hbandDst;
        int tile_size[2] = {0};
+       int _tile_size[2] = {0};
        int ntiles[2] = {1, 1};
        int xtile = 0;
        int ytile = 0;
@@ -1381,12 +1387,25 @@ build_overview(int idx, RTLOADERCFG *config, RASTERINFO *info, int ovx, STRINGBU
        /* tile overview */
        /* each tile is a VRT with constraints set for just the data required for the tile */
        for (ytile = 0; ytile < ntiles[1]; ytile++) {
+
+               /* edge y tile */
+               if (!config->pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
+                       _tile_size[1] = dimOv[1] - (ytile * tile_size[1]);
+               else
+                       _tile_size[1] = tile_size[1];
+
                for (xtile = 0; xtile < ntiles[0]; xtile++) {
                        /*
                        char fn[100];
                        sprintf(fn, "/tmp/ovtile%d.vrt", (ytile * ntiles[0]) + xtile);
                        */
 
+                       /* edge x tile */
+                       if (!config->pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
+                               _tile_size[0] = dimOv[0] - (xtile * tile_size[0]);
+                       else
+                               _tile_size[0] = tile_size[0];
+
                        /* compute tile's upper-left corner */
                        GDALApplyGeoTransform(
                                gtOv,
@@ -1395,7 +1414,7 @@ build_overview(int idx, RTLOADERCFG *config, RASTERINFO *info, int ovx, STRINGBU
                        );
 
                        /* create VRT dataset */
-                       hdsDst = VRTCreate(tile_size[0], tile_size[1]);
+                       hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
                        /*
                        GDALSetDescription(hdsDst, fn);
                        */
@@ -1413,9 +1432,9 @@ build_overview(int idx, RTLOADERCFG *config, RASTERINFO *info, int ovx, STRINGBU
                                VRTAddSimpleSource(
                                        hbandDst, GDALGetRasterBand(hdsOv, j + 1),
                                        xtile * tile_size[0], ytile * tile_size[1],
-                                       tile_size[0], tile_size[1],
+                                       _tile_size[0], _tile_size[1],
                                        0, 0,
-                                       tile_size[0], tile_size[1],
+                                       _tile_size[0], _tile_size[1],
                                        "near", VRT_NODATA_UNSET
                                );
                        }
@@ -1479,6 +1498,7 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
        int nband = 0;
        int i = 0;
        int ntiles[2] = {1, 1};
+       int _tile_size[2] = {0, 0};
        int xtile = 0;
        int ytile = 0;
        double gt[6] = {0.};
@@ -1690,8 +1710,20 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
 
                /* each tile is a raster */
                for (ytile = 0; ytile < ntiles[1]; ytile++) {
+                       /* edge y tile */
+                       if (!config->pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
+                               _tile_size[1] = info->dim[1] - (ytile * info->tile_size[1]);
+                       else
+                               _tile_size[1] = info->tile_size[1];
+
                        for (xtile = 0; xtile < ntiles[0]; xtile++) {
 
+                               /* edge x tile */
+                               if (!config->pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
+                                       _tile_size[0] = info->dim[0] - (xtile * info->tile_size[0]);
+                               else
+                                       _tile_size[0] = info->tile_size[0];
+
                                /* compute tile's upper-left corner */
                                GDALApplyGeoTransform(
                                        info->gt,
@@ -1700,7 +1732,7 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
                                );
 
                                /* create raster object */
-                               rast = rt_raster_new(info->tile_size[0], info->tile_size[1]);
+                               rast = rt_raster_new(_tile_size[0], _tile_size[1]);
                                if (rast == NULL) {
                                        rterror(_("convert_raster: Could not create raster"));
                                        return 0;
@@ -1713,7 +1745,7 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
                                /* add bands */
                                for (i = 0; i < info->nband_count; i++) {
                                        band = rt_band_new_offline(
-                                               info->tile_size[0], info->tile_size[1],
+                                               _tile_size[0], _tile_size[1],
                                                info->bandtype[i],
                                                info->hasnodata[i], info->nodataval[i],
                                                info->nband[i] - 1,
@@ -1774,12 +1806,25 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
 
                /* each tile is a VRT with constraints set for just the data required for the tile */
                for (ytile = 0; ytile < ntiles[1]; ytile++) {
+
+                       /* edge y tile */
+                       if (!config->pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
+                               _tile_size[1] = info->dim[1] - (ytile * info->tile_size[1]);
+                       else
+                               _tile_size[1] = info->tile_size[1];
+
                        for (xtile = 0; xtile < ntiles[0]; xtile++) {
                                /*
                                char fn[100];
                                sprintf(fn, "/tmp/tile%d.vrt", (ytile * ntiles[0]) + xtile);
                                */
 
+                               /* edge x tile */
+                               if (!config->pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
+                                       _tile_size[0] = info->dim[0] - (xtile * info->tile_size[0]);
+                               else
+                                       _tile_size[0] = info->tile_size[0];
+
                                /* compute tile's upper-left corner */
                                GDALApplyGeoTransform(
                                        info->gt,
@@ -1794,7 +1839,7 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
                                */
 
                                /* create VRT dataset */
-                               hdsDst = VRTCreate(info->tile_size[0], info->tile_size[1]);
+                               hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
                                /*
                        GDALSetDescription(hdsDst, fn);
                                */
@@ -1812,9 +1857,9 @@ convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *til
                                        VRTAddSimpleSource(
                                                hbandDst, GDALGetRasterBand(hdsSrc, info->nband[i]),
                                                xtile * info->tile_size[0], ytile * info->tile_size[1],
-                                               info->tile_size[0], info->tile_size[1],
+                                               _tile_size[0], _tile_size[1],
                                                0, 0,
-                                               info->tile_size[0], info->tile_size[1],
+                                               _tile_size[0], _tile_size[1],
                                                "near", VRT_NODATA_UNSET
                                        );
                                }
@@ -2350,6 +2395,10 @@ main(int argc, char **argv) {
                                }
                        }
                }
+               /* pad tiles */
+               else if (CSEQUAL(argv[i], "-P")) {
+                       config->pad_tile = 1;
+               }
                /* out-of-db raster */
                else if (CSEQUAL(argv[i], "-R")) {
                        config->outdb = 1;
index 22dbbd05b9e684d16e82a40face8d2b0e7f6effa..4e7face034ab2dd0e3dabf0b1142418cef63d674 100644 (file)
@@ -103,6 +103,9 @@ typedef struct raster_loader_config {
        /* tile size */
        int tile_size[2];
 
+       /* pad tiles */
+       int pad_tile;
+
        /* register raster as of out-of-db, 1 = yes, 0 = no (default) */
        int outdb;
 
index f476d4da95408b977e87e09d36cc740795530adf..16e9470d964b28073f1720c3b6fa96fefe6d1514 100644 (file)
@@ -122,7 +122,8 @@ TEST_LOADER = \
        loader/Basic \
        loader/BasicCopy \
        loader/Tiled10x10 \
-       loader/Tiled10x10Copy
+       loader/Tiled10x10Copy \
+       loader/Tiled8x8
 
 TESTS = $(TEST_FIRST) $(TEST_METADATA) $(TEST_IO) $(TEST_BASIC_FUNC) \
                $(TEST_PROPS) $(TEST_BANDPROPS) \
diff --git a/raster/test/regress/loader/Tiled8x8-post.pl b/raster/test/regress/loader/Tiled8x8-post.pl
new file mode 100755 (executable)
index 0000000..652b8f6
--- /dev/null
@@ -0,0 +1 @@
+unlink "loader/Tiled8x8.tif";
diff --git a/raster/test/regress/loader/Tiled8x8-post.sh b/raster/test/regress/loader/Tiled8x8-post.sh
new file mode 100755 (executable)
index 0000000..d27c319
--- /dev/null
@@ -0,0 +1 @@
+rm -f loader/Tiled8x8.tif
diff --git a/raster/test/regress/loader/Tiled8x8-pre.pl b/raster/test/regress/loader/Tiled8x8-pre.pl
new file mode 100755 (executable)
index 0000000..4a46970
--- /dev/null
@@ -0,0 +1 @@
+link "loader/testraster.tif", "loader/Tiled8x8.tif";
diff --git a/raster/test/regress/loader/Tiled8x8-pre.sh b/raster/test/regress/loader/Tiled8x8-pre.sh
new file mode 100755 (executable)
index 0000000..95ea884
--- /dev/null
@@ -0,0 +1 @@
+cp loader/testraster.tif loader/Tiled8x8.tif
diff --git a/raster/test/regress/loader/Tiled8x8.opts b/raster/test/regress/loader/Tiled8x8.opts
new file mode 100644 (file)
index 0000000..dba7369
--- /dev/null
@@ -0,0 +1 @@
+-t 8x8 -C
diff --git a/raster/test/regress/loader/Tiled8x8.select.expected b/raster/test/regress/loader/Tiled8x8.select.expected
new file mode 100644 (file)
index 0000000..2483c6b
--- /dev/null
@@ -0,0 +1,5 @@
+0|1.0000000000|-1.0000000000|8|8|t|f|3|{8BUI,8BUI,8BUI}|{NULL,NULL,NULL}|{f,f,f}|POLYGON((0 -90,0 0,90 0,90 -90,0 -90))
+POLYGON((88 0,89 0,89 -1,88 -1,88 0))|255
+POLYGON((88 0,89 0,89 -1,88 -1,88 0))|255
+POLYGON((0 -88,1 -88,1 -89,0 -89,0 -88))|255
+POLYGON((88 -88,89 -88,89 -89,88 -89,88 -88))|255
diff --git a/raster/test/regress/loader/Tiled8x8.select.sql b/raster/test/regress/loader/Tiled8x8.select.sql
new file mode 100644 (file)
index 0000000..a476705
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT srid, scale_x::numeric(16, 10), scale_y::numeric(16, 10), blocksize_x, blocksize_y, same_alignment, regular_blocking, num_bands, pixel_types, nodata_values::numeric(16,10)[], out_db, ST_AsEWKT(extent) FROM raster_columns WHERE r_table_name = 'loadedrast' AND r_raster_column = 'rast';
+SELECT ST_AsEWKT(geom), val FROM (SELECT (ST_PixelAsPolygons(rast, 1)).* FROM loadedrast WHERE rid = 12) foo WHERE x = 1 AND y = 1;
+SELECT ST_AsEWKT(geom), val FROM (SELECT (ST_PixelAsPolygons(rast, 2)).* FROM loadedrast WHERE rid = 12) foo WHERE x = 1 AND y = 1;
+SELECT ST_AsEWKT(geom), val FROM (SELECT (ST_PixelAsPolygons(rast, 2)).* FROM loadedrast WHERE rid = 133) foo WHERE x = 1 AND y = 1;
+SELECT ST_AsEWKT(geom), val FROM (SELECT (ST_PixelAsPolygons(rast, 3)).* FROM loadedrast WHERE rid = 144) foo WHERE x = 1 AND y = 1;