Search code examples
gdal

Is there a way to merge a image pulled from wms and draw a geojson shape on top of it


I want to generate a static image map with some lines drawn on top to be included in an automated email. The line data will be in geojson. I was doing this with an internal mapserver (building a layer that combined an external wms and the data from the postgis db) Now we want to eliminate the mapserver service. Is there a way to possible do this using gdal?


Solution

  • I didn't test it, but I think you should be able to do this in the following two steps:

    First use gdal_translate using the WMS driver to download the image from the remote wms to a georeferenced local image, e.g. a geotiff. The image needs to be georeferenced one way or the other otherwise the 2nd step won't know how/where to burn the vector data in it.

    gdal_translate -of GTiff -projwin -10 55 30 35 -outsize 500 500 external_WMS.xml local_tmp.tif
    

    Then burn the vector.line data from your geojson to the downloaded image using gdal_rasterize. The following sample command burns the relevant vector data from vector.geojson into the RGB geotiff file local_tmp.tif with the color red (RGB = 255,0,0).

    gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 0 -burn 0 -l mask vector.geojson local_tmp.tif