[GIS] Options for displaying PostGIS rasters in OpenLayers

javascriptopenlayers-2PHPpostgis

This question is similar to an earlier question about displaying vector data in a web-map. I want to have a basic web interface which uses OpenLayers and can display raster data that is currently in PostGIS, using a basemap such as google. I have installed PostGIS2.0 with the raster library and see from the documentation that there are several options to output data, such as JPEG, GeoTIFF and PNG. Is their a recommend format to use?

To display vector data I am currently using javascript to send coordinates from the user's browser to my server, and then performing a query using PHP/SQL on PostGIS. The results are then returned as GeoJSON which can be overlaid on the basemap. I wondered if a similar approach could be applied using rasters but I don't know what raster format is best, or if there are any other constraints I should consider.

I have seen a lot of references to GeoServer but I'm not sure if it is necessary for this project (I'm not entirely sure when GeoServer should be used or not).

Best Answer

Rasters are images, so the best format will be an image format (png/jpg/etc). Geojson is a good format for vectors. You will never see, say, your facebook profile pic be transported back as pure json. Of course, returning a url to an image as json is very very different :)

As far as the jpeg vs png vs any other image format discussion, there are tons of different opinions about it. What it boils down to is that some image formats are lossless while others are lossy. Your decision depends on what you are going to do with the data. For analysis you may probably not tolerate lossy, but for displaying things on the web you would.

Can PostGIS 2.0 generate images? Sure. Look at the Raster output section.

Is this a good idea? It really really really depends on what you are doing. Sometimes generating images may take a really really really long time, and you want to cache them to avoid paying the price of generating them every single time you request them through a web environment. The only "caching" you can do on the PostGIS side is to save the results to a different table and then query the table instead when you need it. Geoserver has an entire infrastructure (GeoWebCache) for doing this.

Do you need GeoServer, probably not - but it makes life a lot easier when you have this middleware that exposes all of your data using OGC web services, does caching, styling of vectors and rasters a whole bunch more things.