pggeodb.nancy.inra.fr/db_robot - db_robot on pggeodb.nancy.inra.fr
Previous topic Chapter index Next topic

Function: st_astiff

 

 

Schema

public

 

Owner

albenard

 

Descriptions

args: rast, compression=', srid=sameassource - Return the raster selected bands as a single TIFF image (byte array). If no band is specified, then will try to use all bands.

 

Options

Option

Value

Returns

bytea

Language

plpgsql

Parameters

rast public.raster

compression text

srid integer = NULL::integer

 

Definition

CREATE OR REPLACE FUNCTION public.st_astiff (
 rast public.raster,
 compression text,
 srid integer = NULL::integer
)
RETURNS bytea AS
$span$
DECLARE

compression2 text;
c_type text;
c_level int;
i int;
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
-- JPEG
IF position('JPEG' in compression2) != 0 THEN
c_type := 'JPEG';
c_level := substring(compression2 from '[0-9]+$');

IF c_level IS NOT NULL THEN
IF
c_level > 100 THEN
c_level := 100;
ELSEIF c_level < 1 THEN
c_level := 1;
END IF;

options := array_append(options, 'JPEG_QUALITY=' || c_level);
END IF;

-- per band pixel type check
num_bands := st_numbands($1);
FOR i IN 1..num_bands LOOP
IF st_bandpixeltype($1, i) != '8BUI' THEN
RAISE EXCEPTION
'The pixel type of band % in the raster is not 8BUI.  JPEG compression can only be used with the 8BUI pixel type.', i;
END IF;
END LOOP;

-- DEFLATE
ELSEIF position('DEFLATE' in compression2) != 0 THEN
c_type := 'DEFLATE';
c_level := substring(compression2 from '[0-9]+$');

IF c_level IS NOT NULL THEN
IF
c_level > 9 THEN
c_level := 9;
ELSEIF c_level < 1 THEN
c_level := 1;
END IF;

options := array_append(options, 'ZLEVEL=' || c_level);
END IF;

ELSE
c_type := compression2;

-- CCITT
IF position('CCITT' in compression2) THEN
-- per band pixel type check
num_bands := st_numbands($1);
FOR i IN 1..num_bands LOOP
IF st_bandpixeltype($1, i) != '1BB' THEN
RAISE EXCEPTION
'The pixel type of band % in the raster is not 1BB.  CCITT compression can only be used with the 1BB pixel type.', i;
END IF;
END LOOP;
END IF;

END IF;

-- compression type check
IF ARRAY[c_type] <@ ARRAY['JPEG', 'LZW', 'PACKBITS', 'DEFLATE', 'CCITTRLE', 'CCITTFAX3', 'CCITTFAX4', 'NONE'] THEN
options
:= array_append(options, 'COMPRESS=' || c_type);
ELSE
RAISE NOTICE
'Unknown compression type: %.  The outputted TIFF will not be COMPRESSED.', c_type;
END IF;
END IF;

RETURN st_astiff($1, options, $3);
END;
$span$
LANGUAGE
'plpgsql'
IMMUTABLE
CALLED ON NULL INPUT
SECURITY INVOKER
COST
100;

COMMENT ON FUNCTION public.st_astiff(rast public.raster, compression text, srid integer)
IS 'args: rast, compression='', srid=sameassource - Return the raster selected bands as a single TIFF image (byte array). If no band is specified, then will try to use all bands.';

This file was generated with SQL Manager for PostgreSQL (www.pgsqlmanager.com) at 26/02/2014 11:51
Previous topic Chapter index Next topic