Search code examples
pythongisgdalmapnikcartography

Using Mapnik comp-op to mask out raster layer using a vector layer


I'm trying to make a map with Mapnik using separate datasets for the land and sea.

Land is a raster dataset from Landsat imagery. Ocean is a raster dataset created with gdaldem from NOAA bathymetry.

The Landsat dataset includes ocean imagery, but it's ugly. I want to knock it out so we see thru to the NOAA bathymetry layer below, creating a look similar to the Blue Marble maps.

I thought I could use a third layer containing a PolygonSymbolizer based on a world boundaries vector dataset as a mask, by setting the symbolizer's comp-op to dst_in and dropping it on the very top of a layer stack like this:

  • VECTOR MASK (COMP-OP DST_IN)
  • LAND RASTER
  • SEA RASTER

I've tried every alpha comp mode and can't get it to work. What am I missing? Or maybe there's a much easier way?

Here's a gist of my code... https://gist.github.com/john-sanders/800b973858bc13e4417c


Solution

  • Taking a step back, it seems I was using the wrong tool for the job. Or at least not the easiest tool for the job.

    gdalwarp has a -cutline parameter that accepts a shapefile to knock out unwanted raster data.

    https://gis.stackexchange.com/questions/45053/gdalwarp-cutline-along-with-shapefile

    Also, it appears this question would have been better asked at gis.stackexchange.com