[mapserver-users] RE: Random colours for polygon fill?

pcreso at pcreso.com pcreso at pcreso.com
Wed Jul 6 17:59:14 PDT 2011


Hi Robert,

I have resolved a similar issue with mapserver (where mapserver variable substitution couldn't supply the required functionality) by having a cgi script write the mapfile on the fly, using some logic to customise the mapfile as required. Then the script invokes mapserver with the mapfile.

Sort of:

write mapfile header down to common layer details 
for class in LIST ; do
  write class with random colour
done
close mapfile
invoke mapserver with new mapfile

The issue with this approach is that every invocation will have different colours (unless you always start with the same random seed & use a pseudorandom sequence).


Option 2 is similar. I believe mapserver's runtime variable substitution supports the CLASS expression. A cgi could generate the name/value pairs for the required random colours, append them to the URL query string, invoke mapserver & have mapserver carry out the variable substitution as it preprocesses the mapfile.


Another similar issue I resolved recently: A WMS polygon layer with various but fixed colours & a WFS layer with a point in each polygon with the metadata in OpenLayers.

A table stores the RGB values used in the WMS classes, a query generates a java #hex string from the RGB values, so the WFS layer provides the colour to render each point in, OpenLayers reads the colour for each feature from the WFS fields, so they match the WMS polygons.

The query in the data statement generates java #hex from rgb values, which is fine from postgis, I'm not sure if you can do this from a shapefile, but if so, you could  perhaps predefine your colours in the shapefile, with a value per feature:

geom from (select r.gid + (100 * p.id) as gid,
                            r.gid as r_id,
                            p.id as p_id,
                            r.regioncode,
                            r.regionname,
                            p.geom,
                     ('#'||case when (length(to_hex(r_fill))=1)
                                     then '0'||to_hex(r_fill)
                                     else to_hex(r_fill) end||
                           case when (length(to_hex(g_fill))=1)
                                     then '0'||to_hex(g_fill)
                                     else to_hex(g_fill) end||
                           case when (length(to_hex(b_fill))=1)
                                     then '0'||to_hex(b_fill)
                           else to_hex(b_fill) end) as hex_fill,
                     ('#'||case when (length(to_hex(r_pen))=1)
                                     then '0'||to_hex(r_pen)
                                     else to_hex(r_pen) end||
                           case when (length(to_hex(g_pen))=1)
                                     then '0'||to_hex(g_pen)
                                     else to_hex(g_pen) end||
                           case when (length(to_hex(b_pen))=1)
                                     then '0'||to_hex(b_pen)
                           else to_hex(b_pen) end) as hex_pen
                                                      ...


Cheers,

   Brent
 


Dear Mapserver users



Just wondering if it is possible to colour a polygon Shape file layer with each distinct polygon having a different colour?



Many thanks,



Robert Sanson 


   
This email and any attachments are confidential and intended solely for the addressee(s). If you are not the intended recipient, please notify us immediately and then delete this email
 from your system. 
This message has been scanned for Malware and Viruses by Websense Hosted Security.
www.websense.com 

 

-----Inline Attachment Follows-----

_______________________________________________
mapserver-users mailing list
mapserver-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20110706/7e20ad27/attachment.htm>


More information about the MapServer-users mailing list