[GIS] Dynamic SLD styling – unique colours for linestrings

geoserverpostgissldstyle

I have a postGIS table that looks like this:

(plus a 'track' geometry column, a linestring for the vessel's track)

sampling_interval | voyage_name |   start_time_utc    | id |      ship_name       | start_port | end_port  |           description           |   last_update_utc
------------------+-------------+---------------------+----+----------------------+------------+-----------+---------------------------------+---------------------
                5 | ss2011_e01  | 2011-02-25 23:15:35 | 73 | RV Southern Surveyor | Hobart     | Sydney    | Transit to drydock              | 2011-03-02 02:26:55
                5 | ss2011_v05  | 2011-09-21 06:36:20 | 74 | RV Southern Surveyor | Geraldton  | Geraldton | GA Hydrocarbons                 | 2011-10-17 23:02:25
                5 | ss2012_v01  | 2012-04-20 00:02:45 | 82 | RV Southern Surveyor | Brisbane   | Brisbane  | Sustained monitoring of the EAC | 2012-04-29 05:48:45
                5 | ss2012_t02  | 2012-05-02 03:01:35 | 86 | RV Southern Surveyor | Brisbane   | Lautoka   | Transit Brisbane Lautoka        | 2012-05-09 22:14:00

I have a WMS layer in geoserver pointing to this. What I would like to do is ensure that each vessel track is a distinguishable colour. New voyages are added to this table regularly; if at all possible I would rather not have to edit the SLD next time (and if I do have to edit it, it'd need to be scriptable).

Using a SLD with some logic in it to do this styling seems like the obvious approach, but from looking at the guides/docs, I'm not sure if this is possible (this is really my first exposure to SLDs).

Is this possible/sensible using SLDs? I'm open to other approaches, of course, if there is something that makes more sense. Any pointers appreciated – like I said, I'm very much a newbie with SLDs (but comfortable with postGIS/Geoserver/Java etc)

Best Answer

The easiest answer is to include a column with a colour code in your table that you fill in when you generate the row. You can then use a PropertyValue in the CssParameter tag

   <LineSymbolizer>
     <Stroke>
       <CssParameter name="stroke">
             <ogc:PropertyName>colour</ogc:PropertyName>
       </CssParameter>
       <CssParameter name="stroke-width">2</CssParameter>
     </Stroke>
   </LineSymbolizer>

If you want something that doesn't involve changing the table then you may be able to do something with a transformation function.

Related Question