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

Anzel, Phil - Fort Collins, CO Phil.Anzel at ftc.usda.gov
Wed Jul 6 07:11:22 PDT 2011


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" <Robert.Sanson at asurequality.com>
Subject: [mapserver-users] Random colours for polygon fill?
To: <mapserver-users at lists.osgeo.org>
Message-ID: <4E14260B.379F.0037.1 at asurequality.com>
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




More information about the MapServer-users mailing list