Making use of PgRaster in a simple WMS GetMap handler

As mentioned previously, PgRaster support in GeoServer is not there yet. This is good, because we can learn how to consume it ourselves!

Let's import some data first:

raster2pgsql -s 4326 -C -l 2,4,6,8,10,12,14 -I -F -t 256x256 NE2_HR_LC_SR_W_DR.tif webgis.ne_raster | psql -h localhost -p 5434 -U postgres -d mastering_postgis  

In Chapter 5, Exporting Spatial Data, we used PostgreSQL's large object support to export the raster from the database. We will now build on what we achieved there, so we can come up with a simple raster extractor query for our WMS handler. The interesting bit is the query we used for assembling the tiles of the imported raster back into one raster:

select   ST_Union(rast) ...

Get Mastering PostGIS 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.