From 993eefd8f0b9a25205f05691ba2cbab045951552 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Wed, 27 Mar 2013 13:30:42 +0000 Subject: [PATCH] Fix bad dimensions when rescaling rasters with default geotransform matrix. Ticket #2251 git-svn-id: http://svn.osgeo.org/postgis/trunk@11215 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 2 ++ raster/rt_core/rt_api.c | 14 ++++++++++---- raster/test/regress/rt_gdalwarp.sql | 11 ++++++++++- raster/test/regress/rt_gdalwarp_expected | 10 ++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 9470f9f16..37b7e24af 100644 --- 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 diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 195b8e720..b519701b1 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -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); } diff --git a/raster/test/regress/rt_gdalwarp.sql b/raster/test/regress/rt_gdalwarp.sql index f8fe4eec1..bb20eb6d4 100644 --- a/raster/test/regress/rt_gdalwarp.sql +++ b/raster/test/regress/rt_gdalwarp.sql @@ -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; diff --git a/raster/test/regress/rt_gdalwarp_expected b/raster/test/regress/rt_gdalwarp_expected index 50aaa3cd1..8056e3bff 100644 --- a/raster/test/regress/rt_gdalwarp_expected +++ b/raster/test/regress/rt_gdalwarp_expected @@ -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) -- 2.40.0