MapServer – How to Colour Polygons with Transparent Fill

cartographyfillingmapserverpolygon

Is it possible to fill polygons so that they are completely transparent in MapServer? I want to have a black background that is slightly opaque, and wherever there is a polygon I want that to be completely clear with no fill. I set my background in the following way:

   IMAGECOLOR     0 0 0
   TRANSPARENT OFF

I've tried creating a class that is white to fill the polygon, and experimented with opacity using TRANSPARENCY with values from 0 – 100 but it does not result in a clear polygon:

CLASS
      NAME "light"  
      EXPRESSION ([max_cost] == 2000)     
      STYLE       
        OUTLINECOLOR 255 255 255
        COLOR 255 255 255
        SIZE       1
        WIDTH      2.0        
      END
END 

This is results in the following type of image:

enter image description here

Instead of the polygon having a white fill; I want it to have a fill with no color. I found one suggestion online to define the color like this:

COLOR -1 -1 -1

but it also did not work. In this part of the documentation, the following is described:

“PALETTE=/path/to/palette.txt” is used to define the absolute path
where palette colors can be found. This file must contain 256 entries
of r,g,b triplets for RGB imagemodes, or r,g,b,a quadruplets for RGBA
imagemodes. The expected format is one triplet (or quadruplet) per
line, each value separated by commas, and each triplet/quadruplet on a
single line. If you want to use transparency with a palette, it is
important to have these two colors in the palette file: 0,0,0,0 and
255,255,255,255.

After reading this, I also tried using COLOR 0 0 0 0 but this throws an error:

Unknown identifier. Parsing error near (0):(line 71)

I don't understand how I refer to a define color in PALETTE=/path/to/palette.txt but this seems like one possible way to achieve this.

Best Answer

Mapserver has recently introduced the concept of mask layers (a mask behaves quite like a mask in Photoshop by blending with the layer it is applied to).

The RFC describes what they do and how they can be used. By reading your answer it seems like you could use a mask layer to obtain the 'keyhole' effect you are looking for.

I am not sure if this feature made it into the 6.2 that was released a couple of weeks ago.

Related Question