Tuesday, September 28, 2010

FIX! Geoserver not displaying labels

I've been having an extremely frustrating problem over the last month ... in one word: labeling. My latest labeling challenge, was that Geoserver refused to show labels for many buildings. I tried all kinds of things ... isolating the buildings layer, checking my query order, changing conflicts/overlap options ... pretty much anything I could think of to get labels to display.

Finally, I figured it out! There is an obscured parameter in older ('stable') versions of Geoserver, which was finally exposed through SLD vendorOption in the latest release of Geoserver/Geotools. This parameter MIN_GOODNESS_FIT is used when labeling polygons in particular. Based on MIN_GOODNESS_FIT geotools determines if From geoserver docs:

Geoserver will remove labels if they are a particularly bad fit for the geometry they are labeling.

The label is sampled approximately at every letter. The distance from these points to the polygon is determined and each sample votes based on how close it is to the polygon

so labels are removed if letters are beyond a certain threshold from the polygon. That meant that small buildings (especially ones with longish names) would never be labeled.

However, in Geoserver 2.1 the SLD VendorOption "goodnessOfFit" is exposed

Syntax follows this example:


the default value is 0.5, so anything lower will allow more lables to be placed.

Issue discussion:

1 comment:

-------- said...

Hi Ben, thank you very much for this post. I was struggling to show the label of small polygon and the vendor option was just the one, that I was searching. Cheers!