Ticket #342: st_aspng.3.patch

File st_aspng.3.patch, 7.1 KB (added by dustymugs, 13 months ago)

Updated error messages

  • raster/rt_pg/rtpostgis.sql.in.c

    diff -rupN postgis-old/raster/rt_pg/rtpostgis.sql.in.c postgis-new/raster/rt_pg/rtpostgis.sql.in.c
    old new  
    13291329        LANGUAGE 'SQL' IMMUTABLE STRICT; 
    13301330 
    13311331----------------------------------------------------------------------- 
     1332-- ST_AsPNG 
     1333----------------------------------------------------------------------- 
     1334-- Cannot be strict as "options" can be NULL 
     1335CREATE OR REPLACE FUNCTION st_aspng(rast raster, options text[]) 
     1336        RETURNS bytea 
     1337        AS $$ 
     1338        DECLARE 
     1339                num_bands int; 
     1340                i int; 
     1341                pt text; 
     1342        BEGIN 
     1343                num_bands := st_numbands($1); 
     1344 
     1345                -- PNG only allows 1 or 3 bands 
     1346                IF num_bands > 3 THEN 
     1347                        RAISE NOTICE 'The PNG format only permits one or three bands.  The first three bands will be used.'; 
     1348                        rast := st_band(rast, ARRAY[1, 2, 3]); 
     1349                        num_bands := st_numbands(rast); 
     1350                ELSEIF num_bands > 1 THEN 
     1351                        RAISE NOTICE 'The PNG format only permits one or three bands.  The first band will be used.'; 
     1352                        rast := st_band(rast, ARRAY[1]); 
     1353                        num_bands := st_numbands(rast); 
     1354                END IF; 
     1355 
     1356                -- PNG only supports 8BUI and 16BUI pixeltype 
     1357                FOR i IN 1..num_bands LOOP 
     1358                        pt = st_bandpixeltype(rast, i); 
     1359                        IF pt != '8BUI' AND pt != '16BUI' THEN 
     1360                                RAISE EXCEPTION 'The pixel type of band % in the raster is not 8BUI or 16BUI.  The PNG format can only be used with 8BUI and 16BUI pixel types.', i; 
     1361                        END IF; 
     1362                END LOOP; 
     1363 
     1364                RETURN st_asgdalraster($1, 'PNG', $2, NULL); 
     1365        END; 
     1366        $$ LANGUAGE 'plpgsql' IMMUTABLE; 
     1367 
     1368CREATE OR REPLACE FUNCTION st_aspng(rast raster) 
     1369        RETURNS bytea 
     1370        AS $$ SELECT st_aspng($1, NULL::text[]) $$ 
     1371        LANGUAGE 'SQL' IMMUTABLE STRICT; 
     1372 
     1373CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[], options text[]) 
     1374        RETURNS bytea 
     1375        AS $$ SELECT st_aspng(st_band($1, $2), $3) $$ 
     1376        LANGUAGE 'SQL' IMMUTABLE STRICT; 
     1377 
     1378CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[]) 
     1379        RETURNS bytea 
     1380        AS $$ SELECT st_aspng(st_band($1, $2), NULL::text[]) $$ 
     1381        LANGUAGE 'SQL' IMMUTABLE STRICT; 
     1382 
     1383CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int) 
     1384        RETURNS bytea 
     1385        AS $$ SELECT st_aspng(st_band($1, $2)) $$ 
     1386        LANGUAGE 'SQL' IMMUTABLE STRICT; 
     1387 
     1388CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[], compression int) 
     1389        RETURNS bytea 
     1390        AS $$ 
     1391        DECLARE 
     1392                options text[]; 
     1393        BEGIN 
     1394                IF compression IS NOT NULL THEN 
     1395                        IF compression > 9 THEN 
     1396                                compression := 9; 
     1397                        ELSEIF compression < 1 THEN 
     1398                                compression := 1; 
     1399                        END IF; 
     1400 
     1401                        options := array_append(options, 'ZLEVEL=' || compression); 
     1402                END IF; 
     1403 
     1404                RETURN st_aspng(st_band($1, $2), options); 
     1405        END; 
     1406        $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; 
     1407 
     1408CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int, options text[]) 
     1409        RETURNS bytea 
     1410        AS $$ SELECT st_aspng(st_band($1, $2), $3) $$ 
     1411        LANGUAGE 'SQL' IMMUTABLE STRICT; 
     1412 
     1413CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int, compression int) 
     1414        RETURNS bytea 
     1415        AS $$ SELECT st_aspng($1, ARRAY[$2], $3) $$ 
     1416        LANGUAGE 'SQL' IMMUTABLE STRICT; 
     1417 
     1418----------------------------------------------------------------------- 
    13321419-- MapAlgebra 
    13331420----------------------------------------------------------------------- 
    13341421-- This function can not be STRICT, because nodatavalueexpr can be NULL (could be just '' though) 
  • raster/test/regress/Makefile.in

    diff -rupN postgis-old/raster/test/regress/Makefile.in postgis-new/raster/test/regress/Makefile.in
    old new  
    4545        rt_asgdalraster.sql \ 
    4646        rt_astiff.sql \ 
    4747        rt_asjpeg.sql \ 
     48        rt_aspng.sql \ 
    4849        $(NULL) 
    4950 
    5051TEST_PROPS = \ 
  • raster/test/regress/rt_aspng.sql

    diff -rupN postgis-old/raster/test/regress/rt_aspng.sql postgis-new/raster/test/regress/rt_aspng.sql
    old new  
     1SELECT md5( 
     2        ST_AsPNG( 
     3                ST_AddBand(ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1), 1, '8BSI', 123, NULL) 
     4        ) 
     5); 
     6SELECT md5( 
     7        ST_AsPNG( 
     8                ST_AddBand(ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1), 1, '8BUI', 123, NULL) 
     9        ) 
     10); 
     11SELECT md5( 
     12        ST_AsPNG( 
     13                ST_AddBand(ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1), 1, '8BSI', -123, NULL) 
     14        ) 
     15); 
     16SELECT md5( 
     17        ST_AsPNG( 
     18                ST_AddBand(ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1), 1, '8BUI', 254, NULL) 
     19        ) 
     20); 
     21SELECT md5( 
     22        ST_AsPNG( 
     23                ST_AddBand( 
     24                        ST_AddBand( 
     25                                ST_AddBand( 
     26                                        ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 
     27                                        , 1, '8BSI', 1, -1 
     28                                ) 
     29                                , 2, '8BSI', 11, -1 
     30                        ) 
     31                        , 3, '8BSI', 111, -1 
     32                ), 
     33                ARRAY['ZLEVEL=1'] 
     34        ) 
     35); 
     36SELECT md5( 
     37        ST_AsPNG( 
     38                ST_AddBand( 
     39                        ST_AddBand( 
     40                                ST_AddBand( 
     41                                        ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 
     42                                        , 1, '8BSI', 1, -1 
     43                                ) 
     44                                , 2, '8BSI', 11, -1 
     45                        ) 
     46                        , 3, '8BSI', 111, -1 
     47                ), 
     48                ARRAY['ZLEVEL=9'] 
     49        ) 
     50); 
     51SELECT md5( 
     52        ST_AsPNG( 
     53                ST_AddBand( 
     54                        ST_AddBand( 
     55                                ST_AddBand( 
     56                                        ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 
     57                                        , 1, '8BSI', 1, 1 
     58                                ) 
     59                                , 2, '8BSI', 11, 1 
     60                        ) 
     61                        , 3, '8BSI', 111, 1 
     62                ), 
     63                ARRAY['ZLEVEL=9'] 
     64        ) 
     65); 
     66SELECT md5( 
     67        ST_AsPNG( 
     68                ST_AddBand( 
     69                        ST_AddBand( 
     70                                ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 
     71                                , 1, '8BUI', 1, 1 
     72                        ) 
     73                        , 2, '8BUI', 11, 1 
     74                ), 
     75                ARRAY[1], 
     76                6 
     77        ) 
     78); 
     79SELECT md5( 
     80        ST_AsPNG( 
     81                ST_AddBand( 
     82                        ST_AddBand( 
     83                                ST_AddBand( 
     84                                        ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 
     85                                        , 1, '8BUI', 1, 1 
     86                                ) 
     87                                , 2, '8BUI', 11, 1 
     88                        ) 
     89                        , 3, '8BUI', 111, 1 
     90                ), 
     91                ARRAY[3,1], 
     92                6 
     93        ) 
     94); 
  • raster/test/regress/rt_aspng_expected

    diff -rupN postgis-old/raster/test/regress/rt_aspng_expected postgis-new/raster/test/regress/rt_aspng_expected
    old new  
     1ERROR:  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. 
     255279950e29968bcf36b2c11ce8bf88b 
     3ERROR:  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. 
     424188762b5745acda4aa7b92776e7280 
     5NOTICE:  The PNG format only permits one or three bands.  The first band will be used. 
     6ERROR:  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. 
     7NOTICE:  The PNG format only permits one or three bands.  The first band will be used. 
     8ERROR:  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. 
     9NOTICE:  The PNG format only permits one or three bands.  The first band will be used. 
     10ERROR:  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. 
     11dfff54767aad7aa842f45e5b83326f0b 
     12NOTICE:  The PNG format only permits one or three bands.  The first band will be used. 
     1358168aa11f7ccdf095e5ed02bde1e676