Sunday 27 March 2016

GeoServer VendorOption for SLD to place labels overlapping and out of bounds



I use GeoServer 2.1.1. and have an SLD to serve a layer with labels in OpenLayers. I noticed that some labels are not displayed because other labels are to near. GeoServer wants to make your labels look nice. Weird enough: I don't. Using the VendorOptions in the SLD I figured out some of the problems. I read the SLD cookbook. I am now using:



...
-1
false
...


These two options makes GeoServer draw multiple labels on top of each other even though it will render the labels unreadable (which is what I require).


The problem that still remains is the positioning of the labels. I have the labels set to:






0.5
0.5




But as soon as the labels are to near of the edge of the image/bounds the it no longer centers the labels but will anchor it left or right depending on the position.



My question if someone knows how I can make GeoServer ignore trying to make it look so damn nice (I know it sounds weird!) and just let my labels run out of the image/bounds.



Answer



Check out GeoWebCache, the tile cache engine that comes with GeoServer. You can specify the gutter parameter. According to the docs:



"the gutter parameter is specified in pixels and represents extra padding around the image that is sliced away when the tiles are created. Certain WMS server have edge effects that can be eliminated this way, but it can also result in labels being cut off".



Particularly the last statement indicates this may solve your use case.


Another approach would be to simply request a larger image than the viewport of OpenLayers using the ratio parameter. Thus, labels that appear at the edge of the viewport are still labeled centered on their anchor location as there is still enough of the WMS map image that's simply not visible outside the OL viewport.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...