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

Anzel, Phil - Fort Collins, CO Phil.Anzel at ftc.usda.gov
Wed Jul 6 15:56:43 PDT 2011


Robert,
It may be that the SDE plugin does not allow insertion of the Sql fragment from the COLOR to be executed by the provider. In such a case the solution provided under separate cover by B. Heath Robinson might provide guidance. I do not know if the ArcGIS Server lets you use a view as a data source; if so you could add a calculated column to yield the RGB string (either as a hexadecimal valye as suggested by Heath) or as a string with space-delimited R, G and B values.
FWIW the approach I had suggested worked in MapServer 5.6.2 against Sql Server 2008; beyond that I've not tried it.
- Phil
From: Robert Sanson [mailto:Robert.Sanson at asurequality.com]
Sent: Wednesday, July 06, 2011 4:48 PM
To: Anzel, Phil - Fort Collins, CO; mapserver-users at lists.osgeo.org
Subject: RE: Random colours for polygon fill?

Looks an interesting approach. I tried it with my layer in ArcGIS Server (stored in MS-SQL v 2005) and couldn't get it to work. I am using Mapserver 5.4.2

Here is my layer:

LAYER
  NAME fbnd
  GROUP "CRS"
  TYPE POLYGON
  STATUS ON
  CONNECTIONTYPE SDE
  CONNECTIONTYPE PLUGIN
  PLUGIN "d:/ms4w/apache/specialplugins/msplugin_sde_93.dll"
  CONNECTION "db-esri,port:5155,cadastre,user,pass"
  DATA "CADASTRE.SDEADMIN.VW_FARM_BOUNDARY_SP,SHAPE"
  DUMP TRUE
  HEADER   ../templates/apiaries_query_header.html
  TEMPLATE ../templates/apiaries_query_body.html
  LABELMAXSCALE 100000
  LABELCACHE on
  LABELITEM 'key_decision_maker'
  MAXSCALE 250000
  CLASS
    NAME "fbnd"
    DEBUG on
    STYLE
      WIDTH 3
      #COLOR 135 206 235
      COLOR [convert(varchar(3), ((128 + convert(int,env_min_x)) % 253)) + " " + convert(varchar(3), ((200 + convert(int,env_min_x)) % 254)) + " " + convert(varchar(3), ((64 + convert(int,env_min_x)) % 255))]
      OUTLINECOLOR 0 255 0
    END
    LABEL
      TYPE truetype
      FONT "arial"
      SIZE 9
      POSITION auto
      OUTLINECOLOR 255 255 255 #--Halo
      COLOR 76 179 145
      MINDISTANCE 50
      BUFFER 2
    END #LABEL
  END #CLASS
Many thanks,

Robert

>>> "Anzel, Phil - Fort Collins, CO" <Phil.Anzel at ftc.usda.gov> 7/07/2011 2:11 a.m. >>>
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


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<http://www.websense.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20110706/2a363661/attachment.htm>


More information about the MapServer-users mailing list