Roads and labelling roads

  1. From the Welcome Page navigate to Styles ‣ mainrd in order to edit the mainrd SLD.


    You have to be logged in as Administrator in order to activate this function.

  2. In the SLD Editor find the sld:TextSymbolizer associated to the ogc:PropertyName label_name


    Road style


    The style defines a <Font> and an <Halo> in order to render the value of the property label_name for that layer. The interesting part is at the bottom where several <VendorOption> are specified. Those options are GeoServer specific and allows us to have better and nicer result by tweaking the label renderer behaviour.

Option Description Type

The followLine option forces a label to follow the curve of the line.

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

To use this option place the following in your <TextSymbolizer>. It is required to use <LinePlacement> along with this option to ensure that all labels are correctly following the lines:


With CSS:

-gt-label-follow-line: true;

The repeat option determines how often GeoServer labels a line. Normally GeoServer would label each line only once, regardless of their length. Specify a positive value to make it draw the label every repeat pixels.

<VendorOption name="repeat">100</VendorOption>

With CSS:

-gt-label-repeat: 100;

Sometimes you will have a set of related features that you only want a single label for. The grouping option groups all features with the same label text, then finds a representative geometry for the group.

Roads data is an obvious example - you only want a single label for all of main street, not a label for every piece of main street.


When the grouping option is off (default), grouping is not performed and each geometry is labelled (space permitting).


With the grouping option on, all the geometries with the same label are grouped together and the label position is determined from ALL the geometries.

  • Point Set first point inside the view rectangle is used.
  • Line Set lines are (a) networked together (b) clipped to the view rectangle (c) middle of the longest network path is used.
  • Polygon Set polygons are (a) clipped to the view rectangle (b) the centroid of the largest polygon is used.
<VendorOption name="group">yes</VendorOption>

With CSS:

-gt-label-group: true;


Watch out - you could group together two sets of features by accident. For example, you could create a single group for Paris which contains features for Paris (France) and Paris (Texas).


The maxDisplacement option controls the displacement of the label along a line. Normally GeoServer would label a line at its center point only, provided the location is not busy with another label, and not label it at all otherwise. When set, the labeller will search for another location within maxDisplacement pixels from the pre-computed label point.

When used in conjunction with repeat, the value for maxDisplacement should always be lower than the value for repeat.

<VendorOption name="maxDisplacement">10</VendorOption>

With CSS:

-gt-label-max-displacement: 10;

Another important thing to notice in this style is the road casing, that is, the fact each road segment is painted by two overlapping strokes of different color and size.

Placing the strokes in the two separate feature type styles is crucial:

  • with the symbolizers in two separate FeatureTypeStyle elements all roads are painted with the large stroke, and then again with the thin, lighter one.
  • if instead the two symbolizers were placed in the same FeatureTypeStyle element the result would be different, and not pleasing to see since the renderer would take the first road, paint with the large and thin strokes in sequence, then move to the next one and repeat until the end.

Road casing with a single FeatureTypeStyle element


The Mainrd style in CSS becomes:

[@scale < 500000] {
  stroke: #C08B00, #E3E645;
  stroke-width: 6, 2;
  stroke-linecap: round;
  z-index: 1, 2;

[@scale < 200000] {
  label: [label_name];
  font-fill: #000000;
  font-family: Arial;
  font-size: 13;
  font-style: normal;
  font-weight: bold;
  halo-color: #FFFFFF;
  halo-radius: 1;
  -gt-label-follow-line: true;
  -gt-label-repeat: 400;
  -gt-label-group: true;
  -gt-label-max-displacement: 200;
  z-index: 2;


With the CSS styling there is no need to explicitly declare a property as “VendorOption”.

Please refer to the official documentation for a list of all the supported properties.