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).

4 Answers
4

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.

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.

I understand how to generate an image using PostGIS - what I'm trying to understand is the best way of loading it into Openlayers. For example, if I use ST_AsPNG() - I will still need to identify the upper and lower coordinates where this image is positioned. I thought there might be a neat way of returned a self-contained image that I could directly load into openlayers (aside from using a geoserver).
–
djqOct 11 '11 at 12:46

Yes you can load it directly to openlayers from st_aspng, but it will require extra work. You then have to keep track of the bbox, and specificy it when you load it dev.openlayers.org/apidocs/files/OpenLayers/Layer/Image-js.html Trust me, it is the long route. You are better off letting geoserver or mapserver do this. They give you back WMS/WMTS and you use two lines of code to add it to openlayers.
–
Ragi Yaser BurhumOct 12 '11 at 14:50

Mapserver has support for postgis rasters and directions for a basic setup are given here (item 9.9).

In your case you would setup Mapserver to work as a WMS server so that it returns the Postgis rasters as normal WMS layers. It is then almost trivial to add the layers into your OpenLayers map by using a WMS layer object.

This kind of solution is probably your best option because it is all based on OpenSource software, it's a proven stack and does not require extensive middleware. All mapserver needs is a webserver (the apache you are probably already using for php is ok) that can run cgi scripts.
If performance is not a critical issue then you can avoid using a (tile)cache and just have mapserver render the layers on the fly every time.

If you want to cache the tiles to minimize server load and improve response times consider using mapcache or tilecache. Mapcache is a younger sister project of Mapserver, but should outperform all other caches as it runs as an apache module.

For Ubuntu users the easiest easy way to install Mapserver's dependencies is to add the Ubuntu GIS PPA to your system.

Mapserver is definitely a great alternative from GeoServer (I use it for some other projects). Generally, I pick geoserver for my customers because it has an easy to use interface. Nevertheless, I wanted to point out that serving tile caches is serving static content, and any solution based on nginx (or any other non-blocking server) would be far faster than any apache solution - in either process-based isolation or threaded mode.
–
Ragi Yaser BurhumOct 10 '11 at 19:44

Thanks @unicoletti. Can I use Mapserver if I want to generate rasters based on the users query? For example if I allow users to specify any area (within a certain boundary) will it enable me to make a spatial query of that area?
–
djqOct 10 '11 at 19:45

@celenius Mapserver and GeoServer will both allow you to do that.
–
Ragi Yaser BurhumOct 10 '11 at 21:04

1

@RagiYaserBurhum I compare mapcache to other caches. Static tiles are not strictly speaking a cache.
–
unicolettiOct 11 '11 at 8:39

I think I am stuck with the similar problem. I have some raster data saved in the PostGIS Raster table. Now I want to visualize it on my website, which is based on Openlayers. For the vector data, I can use Geoserver since it has a PostGIS Vector datasource function. But I have no idea how to link the Geoserver to the PostGIS raster table.

@ Ragi Yaser Burhum, How can I add a PostGIS Raster resource in Geoserver. I read from internet that Image Mosaic JDBC could work as an alternatives as PostGIS Raster in Geoserver. But I couldn't get it work. Any Ideas?

@djq. Is your problem solved? Finally, which server did you use. Mapserver or Geoserver, could you also give me some more details.