dynamic legend from raster

Frank Warmerdam warmerdam at POBOX.COM
Mon Dec 5 20:30:43 EST 2005


On 12/5/05, Mark Brooks <mark_brooks at ncsu.edu> wrote:
> I have a raster layer that contains precipitation data.  The layer is
> dynamically created and may contain values from 0 to 2.5  or  0 to 35 or
> 0 to x.  I want my legend of colors, representing thresholds of
> precipitation values, to be dynamic based on the max and min of the
> layer.  So if the precipitation only goes from 0 to 2.5, then my legend
> has its colors evenly divided up within the 0 to 2.5 threshold.  If the
> layer's precipitation goes from 0 to 35, then my legend will have its
> colors evenly divided up within the 0 to 35 threshold.  To potentially
> complicate things, I also want these colors to be dynamically labeled
> based on what thresholds they represent.  I suspect I should use
> something like PROCESSING SCALE_BUCKETS?  I don't know enough about
> scale buckets to know if it's even appropriate for this.

Mark,

In the simplest case of greyscale display of your values, you
could just use PROCESSING "SCALE=AUTO", but for what you
want to do I think you need a different approach.

I think you will need to write some sort of mapscript application
that can query the data, and build a set of classes with appropriate
ranges, names and colors in order to get the desired legend as
well.

MapScript doesn't offer any way to get at raster min/max values,
so you will need another hook for that.  Either some preprocessing
step that puts that information in an associated text file or data base,
or some other sort of scripting calls to query the information.

If you use Python mapscript, then you could also use the GDAL
Python bindings to accomplish this as the GDAL bindings
include mechanisms to get min/max info.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the mapserver-users mailing list