[mapserver-users] Extreme data-driven Symbology with CGI mapserver

Brent Fraser bfraser at geoanalytic.com
Thu Mar 25 14:14:10 EDT 2010


All,

   I'm looking for advice (or at least a reality check).

The short story:
----------------
Can CGI mapserver generate a legend "on the fly" for a varying number of classes 
(class names from a database)?


The Long story:
---------------
  I'm storing feature geometry in a database and I'd like to store symbology 
too.  In theory, this would allow a users/admins to add layers and classes in an 
adhoc manner, and I'd like mapserver (in std CGI mode, I'd like to avoid 
MapScript if possible) to automatically render the features AND produce a 
meaningful standard graphic legend.

   So my database tables would look like:

Tables for storing things:
--------------------------
Geom Table (lots of rows, one per feature):
         pkGeomID    The primary key
         WKT         The WKT/WKB geometry of a feature
         fkClassID   Foreign key to Class table

Class Table (a few rows, for unique symbology):
         pkClassid
         ClassName   A nice name to put in the legend
         fkLayerID   Foreign key to Layer table
         Color       The color of the line (eg "255 0 0")

Layer Table (only a couple of rows, just for organizing the classes):
         pkLayerID
         LayerName   A nice name to put in the legend


And a view, joining the above tables,
so Mapserver can render the features:
--------------------------------------
Render View:
         pkGeomID  WKT   LayerName  ClassName   Color

While this will likely work for rendering the features, I'm doubtful that 
mapserver will be able to keep track of the class names for a legend.  While I 
can set the color from a database attribute:

CLASS
   NAME 'SetByCGI?'
   STYLE
     COLOR [Color]
   END  # Style
END # Class

it is not possible to set the CLASS NAME that way.  It is possible (I think) to 
set it with a CGI variable (something like 
&map.layer[0].Class[0]=NAME+"Trails") but that would not allow for the 
dynamic number of classes.  Or would it?  If I put 10 class defs in my map file, 
then pass as many names as needed (up to 10) in the URL perhaps I could get a 
meaningful legend.

Or maybe WFS is the answer... Or I'll likely need to switch to MapScript.  If 
there's any interest in doing this via CGI, perhaps we could collaborate on an 
enhancement.

Thanks!
Brent Fraser



More information about the mapserver-users mailing list