Book Image

PostGIS Cookbook

Book Image

PostGIS Cookbook

Overview of this book

Table of Contents (18 chapters)
PostGIS Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Sharing and visualizing rasters through SQL


In a previous chapter, we used gdal_translate to export PostGIS rasters to a file. This provides a method for transferring files from one user to another or from one location to another. The only problem with this method is that you may not have access to the gdal_translate utility.

A different but equally functional approach is to use the ST_AsGDALRaster() family of functions available in PostGIS. In addition to ST_AsGDALRaster(), PostGIS provides ST_AsTIFF(), ST_AsPNG(), and ST_AsJPEG() to support the most common raster file formats.

To easily visualize raster files without the need for a GIS application, PostGIS 2.1 and later versions provide ST_ColorMap(). This function applies a built-in or user-specified color palette to a raster that, upon exporting with ST_AsGDALRaster(), can be viewed with any image viewer, such as a web browser.

Getting ready

In this recipe, we will use ST_AsTIFF() and ST_AsPNG() to export rasters to the GeoTIFF and PNG file...