GeoServer Tips & Tricks: Auto alignement of labels within polygons

Labeling polygons can sometimes be tricky. GeoServer ormally places the labels horizontally within the polygon, accepting only labels that “sit” inside the polygon for at least half of their length.
However sometimes the polygons just don’t collaborate with that setup, they can be thin and long, but rotated on an non horizontal angle: in this case GeoServer would not label them until the user zoomed in quite a bit in the map.

Some time ago Björn Hartell and Andrea Aime started working on a patch to add a vendor option auto-rotate the labels for those polygons. After a few iterations and work on both sides we ended up with some pleasing results.
Here is a couple of examples from the well known countries map from Natural Earth labelled with the “minimum bounding rectangle” auto rotation option:

Labelling buildings or parcels is another common usage for this option:

The map was obtained using the following vendor options in the TextSymbolizer section of the SLD:

mbr
20
1.0



The patch just landed in GeoTools, meaning it will be available in the next GeoServer 2.1 beta release.Notice that we have more cartographic rendering improvements in the pipe.

Interested in getting better maps on screen, having some hard rendering problem to tackle? Let us know!

The GeoSolutions team