[GIS] Best way to visualize the PostGIS Raster in OpenLayers

gdalgeoservermapserveropenlayers-2postgis

I have been stuck by this problem for a long time. Several ways have already been tried, but none of them works as I was expecting. Here are the description of each of these method as well as the problem I am facing.

I want to know which is the best option to follow on because I am getting confused now.

Thanks.

  • Method 1: (GDAL + OpenLayers.Layer.Image);

    Convert the PostGIS raster to a tif file first using gdal_translate, and then translate this tif file to image (PNG) file. (Because it is faster than convert it directly from PostGIS to PNG).

    Then, load this image to Openlayers.

  • Problems: Don't know how to make it colorful. Because the default iamge is in gray color. Don't know how to add a color table to this. Real ResultExpected Result

  • Method 2: (MapServer + OpenLayers.Layer.WMS):
    Already get it work in a visual server with 2GB ram. But the problem is the speed. It takes long time to load the data on the map compared with load it as a image file.

    Is that the problem with our virtual server or how the way we set up the MapServer?

  • Method 3: GeoServer + Openlayers.Layer.WMS:

    Cannot get it work yet. Because I don't know how to connect it with PostGIS raster. On the previous Post, it seems we have to connect it to JDBC. But I didn't know someone has ever made it work or not.

Waiting for the help. Thanks.

Best Answer

Since you already have solution 2 (Mapserver+OpenLayers) working I will just suggest how to improve the performance. The key is to add a caching subsystem between mapserver and Open Layers so that when the same imagine is retrieved twice from Mapserver the caching subsystem will return the previously generated one, saving lots of cpu and disk time.

With Mapserver there are several caching subsystems that you can use. For example mapserver has itw own caching module called mapcache.

Another cache that works pretty well, but might require that you install its dependencies is MapProxy.

Last, if you bear with the limitations (in your case it should run just fine, though), you can just enable caching in the Apache http server which runs the mapserver executable. If you already run apache on the server this is by far the fastest way to improve your setup, but it might not always work well with WMS because it is just a generic cache and does not understand the intricacies of WMS.