From 790f448d6d2908b0af95857a81b12ba6878270cd Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 28 Aug 2014 15:15:43 +0000 Subject: [PATCH] Fix output georeference on warping rasters with default georeference Closes #2911 and re-closes #2251 git-svn-id: http://svn.osgeo.org/postgis/trunk@12928 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_warp.c | 9 +++++++++ raster/test/regress/rt_gdalwarp.sql | 4 ++-- raster/test/regress/rt_gdalwarp_expected | 16 ++++++++-------- raster/test/regress/tickets.sql | 15 +++++++++++++-- raster/test/regress/tickets_expected | 4 ++++ 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/raster/rt_core/rt_warp.c b/raster/rt_core/rt_warp.c index 03a9ef1ec..10964c4ff 100644 --- a/raster/rt_core/rt_warp.c +++ b/raster/rt_core/rt_warp.c @@ -29,6 +29,9 @@ * */ +#include "../../postgis_config.h" +//#define POSTGIS_DEBUG_LEVEL 4 + #include "librtcore.h" #include "librtcore_internal.h" @@ -990,6 +993,12 @@ rt_raster rt_raster_gdal_warp( /* substitute spatial, reset back to default */ if (subspatial) { double gt[6] = {0, 1, 0, 0, 0, -1}; + /* See http://trac.osgeo.org/postgis/ticket/2911 */ + /* We should proably also tweak rotation here */ + /* NOTE: the times 10 is because it was divided by 10 in a section above, + * I'm not sure the above division was needed */ + gt[1] = _scale[0] * 10; + gt[5] = -1 * _scale[1] * 10; rt_raster_set_geotransform_matrix(rast, gt); rt_raster_set_srid(rast, SRID_UNKNOWN); diff --git a/raster/test/regress/rt_gdalwarp.sql b/raster/test/regress/rt_gdalwarp.sql index bb20eb6d4..14b7a2f4a 100644 --- a/raster/test/regress/rt_gdalwarp.sql +++ b/raster/test/regress/rt_gdalwarp.sql @@ -835,14 +835,14 @@ SELECT ST_MakeEmptyRaster(1000, 1000, 0, 0, 1, -1, 0, 0, 0) , 1, '8BUI', 255, 0 ) - , 0.25, 0.9 + , 0.25, 0.8 ) AS rast UNION ALL SELECT -- ticket #2188 4 AS rid, ST_Resize( ST_AddBand( - ST_MakeEmptyRaster(1024, 768, 0, 0, 1, -1, 0, 0, 0) + ST_MakeEmptyRaster(1000, 1000, 0, 0, 1, -1, 0, 0, 0) , 1, '8BUI', 255, 0 ) , 0.5, 0.5 diff --git a/raster/test/regress/rt_gdalwarp_expected b/raster/test/regress/rt_gdalwarp_expected index 8056e3bff..df0da040a 100644 --- a/raster/test/regress/rt_gdalwarp_expected +++ b/raster/test/regress/rt_gdalwarp_expected @@ -25,9 +25,9 @@ NOTICE: Values must be provided for both X and Y when specifying the scale. Re 0.22|993310|26|26|1|500.000|500.000|0.000|6.000|950452.000|1396632.000|t|t|t 0.23|984269|12|8|1|0.012|-0.012|0.000|0.000|-107.029|50.206|t|t|t 0.24|974269|12|8|1|0.012|-0.012|0.000|0.000|-107.029|50.206|t|t|t -0.25|0|5|5|1|1.000|-1.000|0.000|0.000|0.000|0.000|t|t|t -0.26|0|2|2|1|1.000|-1.000|0.000|0.000|0.000|0.000|t|t|t -0.27|0|100|100|1|1.000|-1.000|0.000|0.000|0.000|0.000|t|t|t +0.25|0|5|5|1|2.000|-2.000|0.000|0.000|0.000|0.000|t|t|t +0.26|0|2|2|1|5.000|-5.000|0.000|0.000|0.000|0.000|t|t|t +0.27|0|100|100|1|0.100|-0.100|0.000|0.000|0.000|0.000|t|t|t 0.3|994269|12|8|1|0.012|-0.012|0.000|0.000|-107.029|50.206|t|t|t 0.4|993310|24|24|1|500.000|500.000|0.000|0.000|950732.188|1397281.783|t|t|t 0.5|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t @@ -121,10 +121,10 @@ NOTICE: Raster has default geotransform. Adjusting metadata for use of GDAL War 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 +1|0|0|500|500|2|-2|0|0|0|1|250000|63750000|255|0|255|255 +2|0|0|500|100|2|-10|0|0|0|1|50000|12750000|255|0|255|255 +3|0|0|250|800|4|-1.25|0|0|0|1|200000|51000000|255|0|255|255 +4|0|0|500|500|2|-2|0|0|0|1|250000|63750000|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) +(0,0,5,5,2,-2,0,0,0,1)|(0,0,5,5,2,-2,0,0,0,1) diff --git a/raster/test/regress/tickets.sql b/raster/test/regress/tickets.sql index 7ce9c2474..398c61ce0 100644 --- a/raster/test/regress/tickets.sql +++ b/raster/test/regress/tickets.sql @@ -3,5 +3,16 @@ SELECT '#1485', count(*) FROM geometry_columns WHERE f_table_name = 'raster_columns'; -- #2532 -SELECT NULL::raster @ null::geometry; -SELECT NULL::geometry @ null::raster; +SELECT '#2532.1', NULL::raster @ null::geometry; +SELECT '#2532.2', NULL::geometry @ null::raster; + +-- #2911 +WITH data AS ( SELECT '#2911' l, ST_Metadata(ST_Rescale( + ST_AddBand( + ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0), + 1, '8BUI', 0, 0 + ), + 2.0, + -2.0 + )) m +) SELECT l, (m).* FROM data; diff --git a/raster/test/regress/tickets_expected b/raster/test/regress/tickets_expected index 1c1b1e09e..e00841ebf 100644 --- a/raster/test/regress/tickets_expected +++ b/raster/test/regress/tickets_expected @@ -1 +1,5 @@ #1485|0 +#2532.1| +#2532.2| +NOTICE: Raster has default geotransform. Adjusting metadata for use of GDAL Warp API +#2911|0|0|5|5|2|-2|0|0|0|1 -- 2.50.1