Chloropleth maps with Mapserver
Bill Binko
bill at BINKO.NET
Sun Oct 2 13:06:00 PDT 2005
On Sun, 2 Oct 2005, Jason Pickering wrote:
> I am not starting with individual points (well, maybe but the data has
> already been aggregated).
So you have shapefiles or tables in PostGIS that have polygons with your
data in them? I'll assume that for this discussion we're talking about a
table with polygons with an attribute called "IndicatorValue" that holds
your data value.
To draw the maps you're looking for, you'll need to have a layer in your
mapfile that looks something like this:
LAYER
...
CLASS
EXPRESSION 'IndicatorValue < 10'
COLOR 255 0 0 #whatever
END
CLASS
EXPRESSION 'IndicatorValue < 20 AND IndicatorValue >= 10'
COLOR 255 0 0 #whatever
END
...
END
The EXPRESSIONs will vary depending on your source (PostGIS or Shapefiles,
etc).
Your issue is that you want the user to be able to set the number of
classes, and the boundary values (10, 20, etc.).
This is entirely doable right now in Mapserver using Mapscript. There is
no need to wait for the COLORRANGE support that's being discussed on
-devel. That is really being designed for people who want continuous
color changes based on attributes, not just ranges. It's true that some
of the possible approaches there might make this easier, so you might want
to keep an eye on that, but I would not really recommend that you rely on
it.
At its most basic, Mapscript lets you edit a .map file at runtime
programatically before it renders the image. It loads up the .map file
into an object, lets you do stuff like change parameters, add classes,
etc., and then lets you generate the map.
That means that you could have a HTML form that asks them for the # of
groups, and the high/low values and then your script (Python, PHP, Perl,
etc.) could use those to modify your map.
I'm not the Mapscript guru here (there are many), but it doesn't seem that
your request would be much of a challenge.
Now, if you were trying to aggregate points into areas, there would be
other issues. However, it's still doable.
So, choose your poison (PHP, Python, Java, Perl, Ruby, TCL, C#, C++, C)
and ask the list for an example in that language. Someone will respond,
and in a week or so (after you have Mapserver itself running), this should
work.
Hope this helps,
Bill
More information about the MapServer-users
mailing list