]> granicus.if.org Git - postgis/commitdiff
Fix bad dimensions when rescaling rasters with default geotransform
authorBborie Park <bkpark at ucdavis.edu>
Wed, 27 Mar 2013 13:30:42 +0000 (13:30 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 27 Mar 2013 13:30:42 +0000 (13:30 +0000)
matrix. Ticket #2251

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

NEWS
raster/rt_core/rt_api.c
raster/test/regress/rt_gdalwarp.sql
raster/test/regress/rt_gdalwarp_expected

diff --git a/NEWS b/NEWS
index 9470f9f1689ec99e71fd46069368aa6cc768607f..37b7e24afd8103d503295c85db7a206e1d8d3d6a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -159,6 +159,8 @@ PostGIS 2.1.0
            are handled when passing to GDAL Warp API
   - #2215, Fixed raster exclusion constraint for conflicting name of
            implicit index
+  - #2251, Fix bad dimensions when rescaling rasters with default
+           geotransform matrix
 
 PostGIS 2.0.3
 2013/MM/DD
index 195b8e720c33b5f801b96fae1e986e9ab5db959c..b519701b10fe6b9df88fbd1a53a158175c6938db 100644 (file)
@@ -2299,7 +2299,6 @@ rt_errorstate rt_band_get_pixel_line(
        void **vals, uint16_t *nvals
 ) {
        uint8_t *_vals = NULL;
-       rt_pixtype pixtype = PT_END;
        int pixsize = 0;
        uint8_t *data = NULL;
        uint32_t offset = 0; 
@@ -2334,7 +2333,6 @@ rt_errorstate rt_band_get_pixel_line(
        offset = x + (y * band->width);
        RASTER_DEBUGF(4, "offset = %d", offset);
 
-       pixtype = band->pixtype;
        pixsize = rt_pixtype_size(band->pixtype);
        RASTER_DEBUGF(4, "pixsize = %d", pixsize);
 
@@ -3414,7 +3412,6 @@ rt_band_get_histogram(
        double tmp;
        double value;
        int sum = 0;
-       int user_minmax = 0;
        double qmin;
        double qmax;
 
@@ -3452,7 +3449,6 @@ rt_band_get_histogram(
                qmax = stats->max;
        }
        else {
-               user_minmax = 1;
                qmin = min;
                qmax = max;
                if (qmin > qmax) {
@@ -9595,6 +9591,9 @@ rt_raster rt_raster_gdal_warp(
                        FLT_EQ(gt[5], -1)
                ) {
                        double ngt[6] = {0, 10, 0, 0, 0, -10};
+
+                       rtinfo("Raster has default geotransform. Adjusting metadata for use of GDAL Warp API");
+
                        GDALSetGeoTransform(arg->src.ds, ngt);
                        GDALFlushCache(arg->src.ds);
 
@@ -9742,6 +9741,12 @@ rt_raster rt_raster_gdal_warp(
        ) {
                _scale[0] = fabs(*scale_x);
                _scale[1] = fabs(*scale_y);
+
+               /* special override */
+               if (subgt) {
+                       _scale[0] *= 10;
+                       _scale[1] *= 10;
+               }
        }
        else if (
                ((NULL != scale_x) && (NULL == scale_y)) ||
@@ -10275,6 +10280,7 @@ rt_raster rt_raster_gdal_warp(
        /* substitute geotransform matrix, reset back to default */
        if (subgt) {
                double gt[6] = {0, 1, 0, 0, 0, -1};
+
                rt_raster_set_geotransform_matrix(rast, gt);
        }
 
index f8fe4eec17d60fe7ae23537a776667dcb3c68550..bb20eb6d4a24303582dece200026d0bbd7951f1b 100644 (file)
@@ -850,4 +850,13 @@ SELECT -- ticket #2188
 ), bar AS (
        SELECT rid, ST_Metadata(rast) AS meta, ST_SummaryStats(rast) AS stats FROM foo
 )
-SELECT rid, (meta).*, (stats).* FROM bar
+SELECT rid, (meta).*, (stats).* FROM bar;
+
+-- edge case
+WITH foo AS (
+       SELECT ST_AddBand(ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0) AS rast
+)
+SELECT
+       ST_Metadata(ST_Rescale(rast, 2, 2)) AS rescale,
+       ST_Metadata(ST_Resize(rast, 0.5, 0.5)) AS resize
+FROM foo;
index 50aaa3cd1d645002e74289ca936cfd0356dda899..8056e3bffe5d16258fdfcb1f80a048ddf9155e17 100644 (file)
@@ -2,6 +2,9 @@ NOTICE:  table "raster_gdalwarp_src" does not exist, skipping
 NOTICE:  table "raster_gdalwarp_dst" does not exist, skipping
 NOTICE:  Values must be provided for both X and Y when specifying the scale.  Returning original raster
 NOTICE:  Values must be provided for both X and Y when specifying the scale.  Returning original raster
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
 NOTICE:  Values must be provided for both X and Y when specifying the scale.  Returning original raster
 NOTICE:  Values must be provided for both X and Y when specifying the scale.  Returning original raster
 0.0|||||||||||||
@@ -114,7 +117,14 @@ NOTICE:  Values must be provided for both X and Y when specifying the scale.  Re
 5.9|992163|10|11|1|1000.000|-1000.000|0.000|0.000|-500000.000|600009.000|t|t|t
 NOTICE:  The rasters (pixel corner coordinates) are not aligned
 t|f|t
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
 1|0|0|500|500|1|-1|0|0|0|1|250000|63750000|255|0|255|255
 2|0|0|500|100|1|-1|0|0|0|1|50000|12750000|255|0|255|255
 3|0|0|250|900|1|-1|0|0|0|1|225000|57375000|255|0|255|255
 4|0|0|512|384|1|-1|0|0|0|1|196608|50135040|255|0|255|255
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
+NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
+(0,0,5,5,1,-1,0,0,0,1)|(0,0,5,5,1,-1,0,0,0,1)