PostGIS in Action (3rd)
Where the adventure begins

PostGIS in Action: (ed. #1) Chapter 13 - PostGIS Raster

PostGIS In Action 3rd Edition Chapters    PostGIS In Action 2nd Edition Chapters    1st Edition Chapters
Download chapter code and data

The book is out in hard-copy already so what the hell are you waiting for.
PostGIS WKT Raster is now officially part of the upcoming PostGIS 2.0 release and has shed its primordial WKT naming. To celebrate this momentous occasion, this chapter has been renamed PostGIS Raster and has been revised to include some of the newer features in the PostGIS 2.0 (not present in the original WKT Raster).

This chapter is about PostGIS Raster and working with raster data in a PostGIS enabled database. PostGIS WKT Raster is a subproject of PostGIS and currently packaged as a separate install above PostGIS. It introduces a new PostgreSQL data type called raster that interoperates very nicely with the PostGIS geometry and geography types already present. You will be amazed at the many ways you can mix and match raster functions with geometry functions to develop simple plpgsql solutions.

In PostGIS 2.0, the PostGIS Raster has become integrated and renamed to PostGIS Raster and we have windows experimental builds for PostgreSQL 8.4, 9.0, and PostgreSQL 9.1 (beta 1). The rtpostgis-20.dll is still a separate dll in 2.0 (or at least for now).

For PostGIS 1.3-1.5, WKT Raster is a separate .so/.dll file called rtpostgis. Linux/MacOSX users may need to compile their own, but for Windows users, we have experimental precompiled binaries for PostGIS 1.4/1.5 PostgreSQL 8.3/8.4 and the upcoming PostgreSQL 9.0.

The PostGIS 2.0 windows experimental builds, already come packaged with PostGIS raster. It is still a separate dll and separate raster.sql, raster_comments.sql from the postgis-2.0.dll/postgis.sql, postgis_comments.sql. Instructions for installing on windows are available at How to install and configure PostGIS Raster on Windows

For more information about the status PostGIS Raster and its road map, check out WKT Raster Homepage.

A Raster function reference is in progress as well with function list covering many of the functions already supported in PostGIS Raster. Also check out the PostGIS Raster FAQ in progress.

For PostGIS raster we developed a proof of concept ad-hoc spatial raster query viewer which is described in Minimalist Web Based PostGIS 2.0 Raster and Geometry viewer which you can download from: ASP.NET Version and PHP version. The code demonstrates how to utilize the new ST_AsRaster and ST_AsGDALaRaster, PNG," target="_blank">JPEG etc output functions to build a query viewer with nothing but the .NET or PHP PostgreSQL driver to access the data. These new output functions were added after the PostGIS in Action was published so are not covered in Chapter 13 though there future existence was outlined in the book.

Be sure to check out the WKT Raster Roadmap, and of course if you are interested in helping funding the project via time or money so we can cover more, please do so.

Also check out Pierre Racine's tutorial 1 WKT Raster Tutorial 1 which covers ST_Intersects and ST_Intersection for raster/geometry combos. and Jorge Arevalo's Series of PostGIS Raster Tutorials and Oracle GeoRaster contrast and compare

What is covered in this chapter

  • What is raster data and how is it different from vector data.
  • Exercise in loading raster data into PostGIS Raster enabled db and chopping up large rasters into smaller rasters during load.
  • Reading band values with SQL
  • Returning the extent of select Raster rows as a PostGIS geometry polygon
  • Georeferencing rasters
  • Polygonizing rasters based on pixel value ranges and bands.
  • Building custom plpgsql functions that leverage power of both raster and geometry functions.
  • Getting rasters that intersect a geometry and doing intersection operations with raster/geometry
  • Exporting PostGIS raster data type data to other raster file formats using GDAL PostGIS WKT Raster driver.
  • Warping (reprojecting) PostGIS raster data using gdalwarp and outputting to other raster formats
  • How to define PostGIS Raster layers in MapServer
Save 40% off on Third Edition of PostGIS In Action and other Manning published books Offer ends August 19th, 2022
PostGIS in Action,3rd edition pgRouting: a Practical Guide SQL In a Nutshell, 4th Edition