Getting ready

In this recipe, we will use ST_AsTIFF() and ST_AsPNG()to export rasters to GeoTIFF and PNG file formats, respectively. We will also apply the ST_ColorMap() so that we can see them in any image viewer.

To enable GDAL drivers in PostGIS, you should run the following command in pgAdmin:

SET postgis.gdal_enabled_drivers = 'ENABLE_ALL'; 
SELECT short_name
FROM ST_GDALDrivers();

The following queries can be run in a standard SQL client, such as psql or pgAdminIII; however, we can't use the returned output because the output has escaped, and these clients do not undo the escaping. Applications with lower-level API functions can unescape the query output. Examples of this would be a PHP script, a pass-a-record element to pg_unescape_bytea() ...

Get PostGIS Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.