]> granicus.if.org Git - postgis/commitdiff
Fixed handling of SRS strings as they are passed to GDAL functions.
authorBborie Park <bkpark at ucdavis.edu>
Thu, 6 Dec 2012 05:43:59 +0000 (05:43 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 6 Dec 2012 05:43:59 +0000 (05:43 +0000)
Ticket #2134

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

NEWS
raster/rt_core/rt_api.c

diff --git a/NEWS b/NEWS
index 54a4839685ea38cf30a9176d3e5934be1dcdac09..bb7a9954aede06f4e781cd874e2296db0ccbb616 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -120,6 +120,12 @@ PostGIS 2.1.0
   - #2019, ST_FlipCoordinates does not update bbox
   - #2100, ST_AsRaster may not return raster with specified pixel type
 
+PostGIS 2.0.3
+2013/MM/DD
+
+ * Bug Fixes *
+  - #2134, Fixed handling of SRS strings as they are passed to GDAL functions
+
 PostGIS 2.0.2
 2012/12/03
 
@@ -241,7 +247,7 @@ PostGIS 2.0.1
   - #1786, improved build dependencies 
   - #1806, speedup of ST_BuildArea, ST_MakeValid and ST_GetFaceGeometry.
   - #1812, Add lwgeom_normalize in LIBLWGEOM for more stable testing.
-  
+         
 PostGIS 2.0.0
 2012/04/03
    
index 07f1be1cb02dcfb3b6a4a0b2850e6cc92ebab050..6ef2f37746718268dc6c31e15017f148223ea501 100644 (file)
@@ -8489,12 +8489,12 @@ rt_raster_to_gdal(rt_raster raster, const char *srs,
 
        /* any supported format is possible */
        rt_util_gdal_register_all();
-       RASTER_DEBUG(3, "rt_raster_to_gdal: loaded all supported GDAL formats");
+       RASTER_DEBUG(3, "loaded all supported GDAL formats");
 
        /* output format not specified */
        if (format == NULL || !strlen(format))
                format = "GTiff";
-       RASTER_DEBUGF(3, "rt_raster_to_gdal: output format is %s", format);
+       RASTER_DEBUGF(3, "output format is %s", format);
 
        /* load raster into a GDAL MEM raster */
        src_ds = rt_raster_to_gdal_mem(raster, srs, NULL, NULL, 0, &src_drv);
@@ -8510,10 +8510,10 @@ rt_raster_to_gdal(rt_raster raster, const char *srs,
                GDALClose(src_ds);
                return 0;
        }
-       RASTER_DEBUG(3, "rt_raster_to_gdal: Output driver loaded");
+       RASTER_DEBUG(3, "Output driver loaded");
 
        /* convert GDAL MEM raster to output format */
-       RASTER_DEBUG(3, "rt_raster_to_gdal: Copying GDAL MEM raster to memory file in output format");
+       RASTER_DEBUG(3, "Copying GDAL MEM raster to memory file in output format");
        rtn_ds = GDALCreateCopy(
                rtn_drv,
                "/vsimem/out.dat", /* should be fine assuming this is in a process */
@@ -8531,18 +8531,20 @@ rt_raster_to_gdal(rt_raster raster, const char *srs,
 
        /* close source dataset */
        GDALClose(src_ds);
-       RASTER_DEBUG(3, "rt_raster_to_gdal: Closed GDAL MEM raster");
+       RASTER_DEBUG(3, "Closed GDAL MEM raster");
+
+       RASTER_DEBUGF(4, "dataset SRS: %s", GDALGetProjectionRef(rtn_ds));
 
        /* close dataset, this also flushes any pending writes */
        GDALClose(rtn_ds);
-       RASTER_DEBUG(3, "rt_raster_to_gdal: Closed GDAL output raster");
+       RASTER_DEBUG(3, "Closed GDAL output raster");
 
-       RASTER_DEBUG(3, "rt_raster_to_gdal: Done copying GDAL MEM raster to memory file in output format");
+       RASTER_DEBUG(3, "Done copying GDAL MEM raster to memory file in output format");
 
        /* from memory file to buffer */
-       RASTER_DEBUG(3, "rt_raster_to_gdal: Copying GDAL memory file to buffer");
+       RASTER_DEBUG(3, "Copying GDAL memory file to buffer");
        rtn = VSIGetMemFileBuffer("/vsimem/out.dat", &rtn_lenvsi, TRUE);
-       RASTER_DEBUG(3, "rt_raster_to_gdal: Done copying GDAL memory file to buffer");
+       RASTER_DEBUG(3, "Done copying GDAL memory file to buffer");
        if (NULL == rtn) {
                rterror("rt_raster_to_gdal: Unable to create the output GDAL raster");
                return 0;
@@ -8715,13 +8717,21 @@ rt_raster_to_gdal_mem(
 
        /* set spatial reference */
        if (NULL != srs && strlen(srs)) {
-               cplerr = GDALSetProjection(ds, srs);
+               char *_srs = rt_util_gdal_convert_sr(srs, 0);
+               if (_srs == NULL) {
+                       rterror("rt_raster_to_gdal_mem: Unable to convert srs to GDAL accepted format");
+                       GDALClose(ds);
+                       return 0;
+               }
+
+               cplerr = GDALSetProjection(ds, _srs);
+               CPLFree(_srs);
                if (cplerr != CE_None) {
                        rterror("rt_raster_to_gdal_mem: Unable to set projection");
                        GDALClose(ds);
                        return 0;
                }
-               RASTER_DEBUGF(3, "Projection set to: %s", srs);
+               RASTER_DEBUGF(3, "Projection set to: %s", GDALGetProjectionRef(ds));
        }
 
        /* process bandNums */
@@ -9304,6 +9314,14 @@ rt_raster rt_raster_gdal_warp(
                        RASTER_DEBUG(4, "Warp operation does include a reprojection");
                        _src_srs = rt_util_gdal_convert_sr(src_srs, 0);
                        _dst_srs = rt_util_gdal_convert_sr(dst_srs, 0);
+
+                       if (_src_srs == NULL || _dst_srs == NULL) {
+                               rterror("rt_raster_gdal_warp: Unable to convert srs values to GDAL accepted format");
+                               if (_src_srs != NULL) CPLFree(_src_srs);
+                               if (_dst_srs != NULL) CPLFree(_dst_srs);
+
+                               return NULL;
+                       }
                }
                /* no reprojection, a stub just for clarity */
                else {
@@ -11001,7 +11019,10 @@ rt_raster_gdal_rasterize(const unsigned char *wkb,
 
        /* set SRS */
        if (NULL != src_sr) {
-               cplerr = GDALSetProjection(_ds, srs);
+               char *_srs = NULL;
+               OSRExportToWkt(src_sr, &_srs);
+
+               cplerr = GDALSetProjection(_ds, _srs);
                if (cplerr != CE_None) {
                        rterror("rt_raster_gdal_rasterize: Could not set projection on GDALDataset");