]> granicus.if.org Git - postgis/commitdiff
fix NULL raster handling in ST_AsPNG, ST_AsJPEG and ST_AsTIFF
authorBborie Park <bkpark at ucdavis.edu>
Wed, 27 Nov 2013 15:50:14 +0000 (15:50 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 27 Nov 2013 15:50:14 +0000 (15:50 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@12146 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
raster/rt_pg/rtpostgis.sql.in
raster/test/regress/rt_asjpeg.sql
raster/test/regress/rt_asjpeg_expected
raster/test/regress/rt_aspng.sql
raster/test/regress/rt_aspng_expected
raster/test/regress/rt_astiff.sql
raster/test/regress/rt_astiff_expected

diff --git a/NEWS b/NEWS
index 6394b154f5a1ba3fe4d8f7fdf7af65bc78761e04..5fc780261ec6323dfd41d1e0f79dba3ff3743d2a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,8 @@ PostGIS 2.2.0
            raster_columns and raster_overviews
   - #2532, Add missing raster/geometry commutator operators
   - #2540, Change GUC name for GDAL_DATA to postgis.gdal_datapath
+  - #2552, Fix handling of NULL raster in ST_AsTIFF, ST_AsPNG
+           and ST_AsJPEG
 
  * Code refactoring *
 
index bd3b9d7606fb464d8f2638aa1677b0f0d992f5a3..3af7d83d4e6538ceb412620df4b0c4f5f6040764 100644 (file)
@@ -1746,6 +1746,10 @@ CREATE OR REPLACE FUNCTION st_astiff(rast raster, options text[] DEFAULT NULL, s
                nodata double precision;
                last_nodata double precision;
        BEGIN
+               IF rast IS NULL THEN
+                       RETURN NULL;
+               END IF;
+
                num_bands := st_numbands($1);
 
                -- TIFF only allows one NODATA value for ALL bands
@@ -1780,6 +1784,10 @@ CREATE OR REPLACE FUNCTION st_astiff(rast raster, compression text, srid integer
                num_bands int;
                options text[];
        BEGIN
+               IF rast IS NULL THEN
+                       RETURN NULL;
+               END IF;
+
                compression2 := trim(both from upper(compression));
 
                IF length(compression2) > 0 THEN
@@ -1867,6 +1875,10 @@ CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, options text[] DEFAULT NULL)
                num_bands int;
                i int;
        BEGIN
+               IF rast IS NULL THEN
+                       RETURN NULL;
+               END IF;
+
                num_bands := st_numbands($1);
 
                -- JPEG allows 1 or 3 bands
@@ -1942,6 +1954,10 @@ CREATE OR REPLACE FUNCTION st_aspng(rast raster, options text[] DEFAULT NULL)
                i int;
                pt text;
        BEGIN
+               IF rast IS NULL THEN
+                       RETURN NULL;
+               END IF;
+
                num_bands := st_numbands($1);
 
                -- PNG allows 1, 3 or 4 bands
index b1bd59476718b11a1a234a912ab986dc1770e8dc..12ffd5b727d6fb8efed6cbfd5ea3dc3c97d99371 100644 (file)
@@ -1,3 +1,4 @@
+SELECT ST_AsJPEG(NULL) IS NULL;
 SELECT CASE
        WHEN length(
                ST_AsJPEG(
index e441e972587d17a3a5afe010d76159b372f8c7dc..3131f34621f8c22f9fa2e9aabdae39916ac4c9d2 100644 (file)
@@ -1,3 +1,4 @@
+t
 ERROR:  The pixel type of band 1 in the raster is not 8BUI.  The JPEG format can only be used with the 8BUI pixel type.
 1
 ERROR:  The pixel type of band 1 in the raster is not 8BUI.  The JPEG format can only be used with the 8BUI pixel type.
index e063f53e51141c0d5ab826469373ad87710dfeb2..60e6f71383daa1d4eb1600878473268b7f389e81 100644 (file)
@@ -1,3 +1,4 @@
+SELECT ST_AsPNG(NULL) IS NULL;
 SELECT CASE
        WHEN length(
                ST_AsPNG(
index 430febc8f24ada89534934e208fa58058c81b574..92345d5573c37e13ad547261320e137b627cfb4a 100644 (file)
@@ -1,3 +1,4 @@
+t
 ERROR:  The pixel type of band 1 in the raster is not 8BUI or 16BUI.  The PNG format can only be used with 8BUI and 16BUI pixel types.
 1
 ERROR:  The pixel type of band 1 in the raster is not 8BUI or 16BUI.  The PNG format can only be used with 8BUI and 16BUI pixel types.
index 0f05bbd8a46b364dc259e4ecede5774c7df6589e..f59fccf1ce37d22fd670d811430a3766ecc20916 100644 (file)
@@ -1,3 +1,5 @@
+SELECT ST_AsTIFF(NULL) IS NULL;
+SELECT ST_AsTIFF(NULL, 'JPEG') IS NULL;
 SELECT CASE
        WHEN length(
                ST_AsTIFF(
index 0387b83125e29f9b1c6cf04f8a5cef480d03d865..44ba5c48f0411d467d095c8113628ec57f162300 100644 (file)
@@ -1,3 +1,5 @@
+t
+t
 1
 1
 1