Hi, Robert,

A simple approach would be to generate a pseudo-random color based upon a value 
unique to each record in your source data. For example, in the following 
example the source data, pulled from a Microsoft Sql Server database, has an 
integer column named "ShapeID":

  layer
    name "mupolygon"
    status on
    connectiontype plugin
    plugin "C:/ms4w/Apache/specialplugins/msplugin_mssql2008.dll"
    processing "CLOSE_CONNECTION=DEFER"
    connection "server=...;"
    projection 'init=epsg:4269' END   # NAD83
    units DD
    DATA "shapeGeometry from soilmu_a_wy721_nad83 using unique shapeID using 
SRID=4269"
    type polygon
    opacity 40
    class
      name "mupoly"
      style
        COLOR [convert(varchar(3), (128 + shapeID) % 253) + ' ' + 
convert(varchar(3), (200 + shapeID) % 254) + ' ' + convert(varchar(3), (64 + 
shapeID) % 255)]
        outlinecolor 0 0 0
        outlinewidth 1
      end
    end  # of class "mupoly"
  end # of layer "mupolygon"

In the context used above, the content of COLOR's specification (everything 
between the square brackets) is passed on as part of the SQL statement 
generated and transmitted to the database engine. Many variations are possible. 
Note that this approach does not provide any protection against the unlikely 
case where adjacent polygons display the same color.

I cannot speak to using data from other data sources. Best of luck with this.

- Phil Anzel
  Web Soil Survey developer
  Vistronix Inc for USDA/NRCS/ITC


-----Original Message-----

------------------------------

Message: 4
Date: Wed, 06 Jul 2011 09:08:28 +1200
From: "Robert Sanson" <[email protected]>
Subject: [mapserver-users] Random colours for polygon fill?
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

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

_______________________________________________
mapserver-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapserver-users

Reply via email to