From: Bborie Park Date: Fri, 15 Feb 2013 23:53:32 +0000 (+0000) Subject: Changed how rasters with unknown SRID and default geotransform are X-Git-Tag: 2.1.0beta2~209 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac3a63c074cbcf11b9f5fe65028a83c0c355b7d4;p=postgis Changed how rasters with unknown SRID and default geotransform are handled when calling GDAL Warp API. Ticket #2203 git-svn-id: http://svn.osgeo.org/postgis/trunk@11094 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 57b66233e..869dedf40 100644 --- a/NEWS +++ b/NEWS @@ -142,6 +142,8 @@ PostGIS 2.1.0 when copying data from a GDAL dataset - #2198, Fix incorrect dimensions used when generating bands of out-db rasters in ST_Tile() + - #2203, Changed how rasters with unknown SRID and default geotransform + are handled when passing to GDAL Warp API PostGIS 2.0.3 2013/MM/DD diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index a63bc29bb..4399c7ff4 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -9474,7 +9474,6 @@ rt_raster rt_raster_gdal_warp( double *skew_x, double *skew_y, GDALResampleAlg resample_alg, double max_err ) { - // keep these CPLErr cplerr; char *dst_options[] = {"SUBCLASS=VRTWarpedDataset", NULL}; _rti_warp_arg arg = NULL; @@ -9500,6 +9499,8 @@ rt_raster rt_raster_gdal_warp( int i = 0; int numBands = 0; + int subgt = 0; + RASTER_DEBUG(3, "starting"); assert(NULL != raster); @@ -9554,6 +9555,26 @@ rt_raster rt_raster_gdal_warp( } RASTER_DEBUG(3, "raster loaded into GDAL MEM dataset"); + /* special case when src_srs and dst_srs is NULL and raster's geotransform matrix is default */ + if (src_srs == NULL && dst_srs == NULL && rt_raster_get_srid(raster) == SRID_UNKNOWN) { + double gt[6]; + + /* default geotransform */ + rt_raster_get_geotransform_matrix(raster, gt); + if ( + FLT_EQ(gt[0], 0) && + FLT_EQ(gt[1], 1) && + FLT_EQ(gt[2], 0) && + FLT_EQ(gt[3], 0) && + FLT_EQ(gt[4], 0) && + FLT_EQ(gt[5], -1) + ) { + double ngt[6] = {0, 10, 0, 0, 0, -10}; + GDALSetGeoTransform(arg->src.ds, ngt); + subgt = 1; + } + } + /* set transform options */ if (arg->src.srs != NULL || arg->dst.srs != NULL) { arg->transform.option.len = 2; @@ -10218,6 +10239,12 @@ rt_raster rt_raster_gdal_warp( return NULL; } + /* 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); + } + RASTER_DEBUG(3, "done"); return rast; diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 141d4eb49..69366cb5f 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -11341,24 +11341,6 @@ Datum RASTER_GDALWarp(PG_FUNCTION_ARGS) } /* target SRID == src SRID, no reprojection */ else if (dst_srid == src_srid) { - /* set geotransform BUT ONLY when geotransform IS the default */ - if (src_srid == SRID_UNKNOWN) { - double gt[6]; - - rt_raster_get_geotransform_matrix(raster, gt); - if ( - FLT_EQ(gt[0], 0) && - FLT_EQ(gt[1], 1) && - FLT_EQ(gt[2], 0) && - FLT_EQ(gt[3], 0) && - FLT_EQ(gt[4], 0) && - FLT_EQ(gt[5], -1) - ) { - double ngt[6] = {0, 10, 0, 0, 0, -10}; - rt_raster_set_geotransform_matrix(raster, ngt); - } - } - no_srid = 1; } @@ -11502,11 +11484,6 @@ Datum RASTER_GDALWarp(PG_FUNCTION_ARGS) /* add target SRID */ rt_raster_set_srid(rast, dst_srid); - if (no_srid && src_srid == SRID_UNKNOWN) { - double gt[6] = {0, 1, 0, 0, 0, -1}; - rt_raster_set_geotransform_matrix(rast, gt); - } - pgrast = rt_raster_serialize(rast); rt_raster_destroy(rast); diff --git a/raster/test/regress/rt_gdalwarp.sql b/raster/test/regress/rt_gdalwarp.sql index b755b404d..f8fe4eec1 100644 --- a/raster/test/regress/rt_gdalwarp.sql +++ b/raster/test/regress/rt_gdalwarp.sql @@ -244,7 +244,7 @@ INSERT INTO raster_gdalwarp_dst (rid, rast) VALUES ( ) FROM raster_gdalwarp_src) ), ( 0.25, (SELECT _st_gdalwarp( - ST_SetSRID(rast, 0), + ST_SetGeoReference(ST_SetSRID(rast, 0), '1 0 0 -1 0 0'), 'NearestNeighbor', 0.125, NULL, NULL, NULL, @@ -254,7 +254,7 @@ INSERT INTO raster_gdalwarp_dst (rid, rast) VALUES ( ) FROM raster_gdalwarp_src) ), ( 0.26, (SELECT _st_gdalwarp( - ST_SetSRID(rast, 0), + ST_SetGeoReference(ST_SetSRID(rast, 0), '1 0 0 -1 0 0'), 'NearestNeighbor', 0.125, NULL, NULL, NULL, @@ -264,7 +264,7 @@ INSERT INTO raster_gdalwarp_dst (rid, rast) VALUES ( ) FROM raster_gdalwarp_src) ), ( 0.27, (SELECT _st_gdalwarp( - ST_SetSRID(rast, 0), + ST_SetGeoReference(ST_SetSRID(rast, 0), '1 0 0 -1 0 0'), 'NearestNeighbor', 0.125, NULL, NULL, NULL,