Throw GeoServer a curve (and it will be labeled)

Improvements to GeoServer are being made all the time, but to the average user, not all improvements are immediately discernible. However, recently a new feature has been added to GeoServer’s rendering algorithms, and all I can say is “wow.” I am referring to curved line labeling.

Labels on lines have rendering challenges that points and polygons do not. This is because lines can curve. Not officially, of course, but lines can be a collection of line segments, which meet at their edges but can be rotated with respect to each other. The default behavior for a label is to appear parallel to the orientation of a line. However, this can cause problems when the label resides along a curve, as the label will not follow it. In some extreme cases, the label can appear only marginally connected to the line, which minimizes the effectiveness of the label! Clearly, there was room for improvement.

This improvement was sponsored by TriMet, the Portland, Oregon area transportation agency that uses GeoServer in their Trip Planner. Lead GeoServer developer Andrea Aime tackled this task with his usual aplomb, and GeoServer now renders labels that follow curves. Below is worth two thousand words:



This new road labeling is only in versions 1.7.1 and later. Currently this functionality is not turned on by default, but is instead must be enabled in GeoServer. One way of doing this is to edit your web.xml file inside the WEB-INF directory. Stop your GeoServer instance, and insert the following code block:

<context-param>
<param-name>USE_NG_LABELLER</param-name>
<param-value>true</param-value>
</context-param>

In addition, you also need to edit your SLD to include a VendorOption inside your TextSymbolizer. Add the following line:

<VendorOption name="followLine">true</VendorOption>

Restart your GeoServer, and you’re all set!

For me, the ability for GeoServer to output curved line labels is a huge step forward. There’s something about these labels that make the map seem so much more professional. Special thanks to TriMet for sponsoring this awesome new feature. Have you tried it out yet?

6 Comments

  1. Stefan Ziegler
    Posted 2009/01/08 at 4:17 pm | Permalink

    Just tried it out and it looks really fantastic. A big thank you to TriMet and Andrea!

  2. Posted 2009/01/09 at 4:21 am | Permalink

    Thanks Stefan.
    Actually if you look at the screenshots there are three more features shown:
    - automatic label wrapping, if the label exceeds a certain length it will be wrapped on multiple lines
    - label displacement, in which the label gets moved along the line if the middle of the line is “busy” with another conflicting label
    - label repetition, that allows to repeat the same label each x pixels, and which helps in labeling long linear features

  3. Jorge Gustavo
    Posted 2009/01/27 at 11:16 pm | Permalink

    Andrea, you are the best!

    I’ve tried it and it looks very nice.
    I was able to produce curved labels in a completely fresh geoserver installation (version 1.7.2). So, the mentioned parameter USE_NG_LABELLER seems to be unnecessary, right?

    Regards, Jorge

  4. Posted 2009/02/17 at 3:48 pm | Permalink

    This is a very nice tool, the maps are really improved with the curvet Labels.

    http://www.osm-wms.de

  5. Zontar
    Posted 2009/06/25 at 10:37 am | Permalink

    I tried to use “followLine” with PerpendicularOffset and
    it´s not working together..

  6. Nic
    Posted 2009/10/21 at 9:37 am | Permalink

    Thanks Andrea for the curve labels, it helped allot.
    I was also just wondering if there is a method to smooth lines which cross or join each other? If there is anyone who can help me with that, it will be deeply apreciated. Thanks

    Nic

Download GeoServer