6

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)

1 Answer 1

3

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.

2
  • 1
    Thanks. Yeah, I thought about using a column with colours in it, but I don't want to tie styling information to my data if I can help it. I'll have a bit of a poke around functions in SLD - looks like it might be the go, even if I have to write my own. I'll update this post with whatever solution I eventually go for. Thanks for your help.
    – Caligari
    Commented Dec 20, 2012 at 6:23
  • 1
    I agree with Ian that's the best avenue. Just creating a filter function might be another way, but you would have to create something that returns the same color for the same feature every time it's called.. maybe something based on hashing the feature contents and boiling it down to a color, but... there is no guarantee you'll get anything aesthetically pleasing, or that the colors you'll get are unique (the hash might collide) or humanly discernible (distinct colors, but too close for a human to tell apart) Commented Dec 23, 2012 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.