Name

ST_AsGDALRaster — Return the raster tile in the designated GDAL Raster format. Raster formats are one of those supported by your compiled library. Use ST_GDALDrivers() to get a list of formats supported by your library.

Synopsis

bytea ST_AsGDALRaster(raster rast, text format, text[] options=NULL, integer srid=sameassource);

Descrição

Retorna a tile raster no formato designado. Os argumentos estão listados abaixo:

  • format formato para saída. Isso depende dos drivers compilados na sua biblioteca libgdal. Estão normalmente disponíveis 'JPEG', 'GTIff', 'PNG'. Use ST_GDALDrivers para conseguir uma lista dos formatos suportados por sua biblioteca.

  • options texto arranjo de opções GDAL. As opções válidas são dependentes do formato. Recorra a GDAL Raster format options para mais detalhes.

  • srs O proj4text ou srtext (do spatial_ref_sys) para embutir na imagem

Disponibilidade: 2.0.0 - requer GDAL >= 1.6.0.

JPEG Output Example, multiple tiles as single raster

SELECT ST_AsGDALRaster(ST_Union(rast), 'JPEG', ARRAY['QUALITY=50']) As rastjpg
FROM dummy_rast
WHERE rast && ST_MakeEnvelope(10, 10, 11, 11);

Using PostgreSQL Large Object Support to export raster

One way to export raster into another format is using PostgreSQL large object export functions. We'lll repeat the prior example but also exporting. Note for this you'll need to have super user access to db since it uses server side lo functions. It will also export to path on server network. If you need export locally, use the psql equivalent lo_ functions which export to the local file system instead of the server file system.

DROP TABLE IF EXISTS tmp_out ;

CREATE TABLE tmp_out AS
SELECT lo_from_bytea(0,
       ST_AsGDALRaster(ST_Union(rast), 'JPEG', ARRAY['QUALITY=50'])
        ) AS loid
  FROM dummy_rast
WHERE rast && ST_MakeEnvelope(10, 10, 11, 11);

SELECT lo_export(loid, '/tmp/dummy.jpg')
   FROM tmp_out;

SELECT lo_unlink(loid)
  FROM tmp_out;

GTIFF Output Examples

SELECT ST_AsGDALRaster(rast, 'GTiff') As rastjpg
FROM dummy_rast WHERE rid=2;

-- Out GeoTiff with jpeg compression, 90% quality
SELECT ST_AsGDALRaster(rast, 'GTiff',
  ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'],
  4269) As rasttiff
FROM dummy_rast WHERE rid=2;