]> granicus.if.org Git - postgis/commitdiff
Changed how rasters with unknown SRID and default geotransform are
authorBborie Park <bkpark at ucdavis.edu>
Fri, 15 Feb 2013 23:53:32 +0000 (23:53 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Fri, 15 Feb 2013 23:53:32 +0000 (23:53 +0000)
handled when calling GDAL Warp API. Ticket #2203

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

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

diff --git a/NEWS b/NEWS
index 57b66233e5fec0511f39a5205be36eedff4e0776..869dedf4080e49272b615cceb76b6331fdf3fb30 100644 (file)
--- 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
index a63bc29bb4dd9da0ccb842b268c9a7bd7d31fea2..4399c7ff446f9efa75f67a919dc1dec0fd0703c6 100644 (file)
@@ -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;
index 141d4eb49e2a7db96cac3598bec1ccd6e8a22da5..69366cb5fa289e810a7b2fd9e6d6d2d135fc7b5b 100644 (file)
@@ -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);
 
index b755b404d5274d819fb558e85c30b84ac1fce621..f8fe4eec17d60fe7ae23537a776667dcb3c68550 100644 (file)
@@ -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,