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
Hi Roger:
ReplyDeleteFirstly, congratulations for your blog, you really tackle nice topics, good content and clear explanations about GIS. MapServer is a powerful tool to render WMS maps but simetimes is horrible due to the fact that updated doc is missing in official documentation and people have to find some solutions for concrete problems.
Regarding your entry, I have a question with legends for colour maps for rasters in Mapserver and I was wondering if you could throw some light with colour maps in MapSevrer for a generic raster like Radar displayed layers. I envy your horizontal colorramp bar.
I used SLD styles enabling SLD format in mapfile's metadata description but without success.
I tried with CLASSES defined in layer-based file, like this:
CLASS
NAME "ColorMap"
EXPRESSION ([pixel] >=0.0 AND [pixel] <=1.0)
STYLE
COLORRANGE 0 0 0 255 255 255
DATARANGE 0.0 1.0
RANGEITEM "pixel"
END
END
and I got desired visualisation but generated legend
http://servername/ogc/wms?version=1.3.0&service=WMS&request=GetLegendGraphic&sld_version=1.1.0&layer=LAND_NAME&format=image/png&STYLE=default
is not ramp scaled. Only a squared box without colour and "ColorMap" label.
Have you got some ideas about this inconvenience?
Thank you in advance
Jorge López
Hola Jorge!
ReplyDeleteI haven't tried exacly this with mapserver, but legends have given me problems also when creating some vector symbols.
So, just making a guess, mapserver draws the legend using one color square or symbol for every class. Since you have only one class, no squares can be made.
There are ways to force the legend values to be different from the classes used to draw, like using the KEYIMAGE key in the CLASS section.
Also, html legends can be set to make complicated legends:
http://mapserver.org/output/html_legend.html
I can't give you a better answer...
Thanks Roger,
DeleteI will give a try one again trying to generate legend, otherwise I can attach a pre-generated image for legend. If success, I will inform you about the solution.
See you
Jorge
Great blog you havve here
ReplyDelete