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:
The map was obtained using the following vendor options in the TextSymbolizer section of the SLD:
Interested in getting better maps on screen, having some hard rendering problem to tackle? Let us know!