From dfd95c1afd3236f6219328a414a80d8961a14ce2 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Sat, 2 Nov 2013 21:03:06 +0000 Subject: [PATCH] changed behavior of how non-spatially referenced rasters are handled git-svn-id: http://svn.osgeo.org/postgis/trunk@12076 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_warp.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/raster/rt_core/rt_warp.c b/raster/rt_core/rt_warp.c index 43b7752d4..854d179b5 100644 --- a/raster/rt_core/rt_warp.c +++ b/raster/rt_core/rt_warp.c @@ -4,6 +4,7 @@ * WKTRaster - Raster Types for PostGIS * http://trac.osgeo.org/postgis/wiki/WKTRaster * + * Copyright (C) 2013 Bborie Park * Copyright (C) 2011-2013 Regents of the University of California * * Copyright (C) 2010-2011 Jorge Arevalo @@ -194,7 +195,8 @@ rt_raster rt_raster_gdal_warp( int i = 0; int numBands = 0; - int subgt = 0; + /* flag indicating that the spatial info is being substituted */ + int subspatial = 0; RASTER_DEBUG(3, "starting"); @@ -251,7 +253,10 @@ 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) { + if ( + src_srs == NULL && dst_srs == NULL && + rt_raster_get_srid(raster) == SRID_UNKNOWN + ) { double gt[6]; #if POSTGIS_DEBUG_LEVEL > 3 @@ -265,6 +270,7 @@ rt_raster rt_raster_gdal_warp( RASTER_DEBUGF(3, "raster geotransform: %f, %f, %f, %f, %f, %f", gt[0], gt[1], gt[2], gt[3], gt[4], gt[5]); + /* substitute spatial info (lack of) with a real one EPSG:32731 (WGS84/UTM zone 31s) */ if ( FLT_EQ(gt[0], 0) && FLT_EQ(gt[1], 1) && @@ -273,14 +279,18 @@ rt_raster rt_raster_gdal_warp( FLT_EQ(gt[4], 0) && FLT_EQ(gt[5], -1) ) { - double ngt[6] = {0, 10, 0, 0, 0, -10}; + double ngt[6] = {166021.4431, 0.1, 0, 10000000.0000, 0, -0.1}; rtinfo("Raster has default geotransform. Adjusting metadata for use of GDAL Warp API"); + subspatial = 1; + GDALSetGeoTransform(arg->src.ds, ngt); GDALFlushCache(arg->src.ds); - subgt = 1; + /* EPSG:32731 */ + arg->src.srs = rt_util_gdal_convert_sr("EPSG:32731", 0); + arg->dst.srs = rt_util_gdal_convert_sr("EPSG:32731", 0); #if POSTGIS_DEBUG_LEVEL > 3 GDALGetGeoTransform(arg->src.ds, gt); @@ -425,10 +435,14 @@ rt_raster rt_raster_gdal_warp( _scale[0] = fabs(*scale_x); _scale[1] = fabs(*scale_y); - /* special override */ - if (subgt) { + /* special override since we changed the original GT scales */ + if (subspatial) { + /* _scale[0] *= 10; _scale[1] *= 10; + */ + _scale[0] /= 10; + _scale[1] /= 10; } } else if ( @@ -960,11 +974,12 @@ rt_raster rt_raster_gdal_warp( return NULL; } - /* substitute geotransform matrix, reset back to default */ - if (subgt) { + /* substitute spatial, reset back to default */ + if (subspatial) { double gt[6] = {0, 1, 0, 0, 0, -1}; rt_raster_set_geotransform_matrix(rast, gt); + rt_raster_set_srid(rast, SRID_UNKNOWN); } RASTER_DEBUG(3, "done"); -- 2.50.1