MapServer is a great way to draw web maps, using it either as a WMS server or creating image files directly.
Is the raster has a No Data value, MapServer reads it from the GDAL library and doesn't draw the pixels with the value. But what happens if you want to draw the pixels with No Data values?
Once this is done, just create a CLASS with the No Data Value ¡in the EXPRESSION tag, so the pixels are coloured as you prefer.
Strangely, finding the solution was quite difficult, so I put it in this post. Maybe somebody, someday, will find faster than me.
Is the raster has a No Data value, MapServer reads it from the GDAL library and doesn't draw the pixels with the value. But what happens if you want to draw the pixels with No Data values?
Fast answer
The solution, that I found here, is setting the LAYER property PROCESSING in this way:
which disables the regular MapServer behaviour, which is, quite logically, not drawing the pixels with the NODATA value.
PROCESSING "NODATA=OFF"
Once this is done, just create a CLASS with the No Data Value ¡in the EXPRESSION tag, so the pixels are coloured as you prefer.
Why did I need this stuff
Maybe this is not a common need, but when drawing weather radar images, is a good idea to indicate the areas not covered by the radar in some colour, so it's easy to distinguish between zones where there is no rain from the zones where no data is available. Like in these examples:
The Catalan Weather Service radar in La Panadella with the range visible in gray, using the no data values
The Spanish Agency radar network, with the not covered areas in gray.
Strangely, finding the solution was quite difficult, so I put it in this post. Maybe somebody, someday, will find faster than me.
Some links:
- The only place I found some documentation about this topic: http://trac.osgeo.org/mapserver/ticket/2404
- The Accueather web site, showing the radar network without shading the not covered areas
- Hawaii Doppler Radar visualization with the nodata zone visible
- The entry about the GDAL IRIS driver
- MapServer raster documentation page