When creating labels using centroids of a polygon layer, I'm facing the problem that some of them are missing. Eg:

Missing labels

Ok, I can make it reappear by using "maxDisplacement" vendor option, but, using this option labels appear displaced. Some to the right, some to the left.

Displaced labels

How can I render all the labels propperly in the centroid of the polygons?

Here is the SLD code I'm using:

<?xml version="1.0" encoding="UTF-8"?>
<sld:UserStyle xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">
           <CssParameter name="fill">#40FF40</CssParameter>
           <CssParameter name="stroke">#FFFFFF</CssParameter>
           <CssParameter name="stroke-width">2</CssParameter>
          <ogc:Function name="centroid">
           <CssParameter name="font-family">Arial</CssParameter>
           <CssParameter name="font-size">11</CssParameter>
           <CssParameter name="font-style">normal</CssParameter>
           <CssParameter name="font-weight">bold</CssParameter>
           <CssParameter name="fill">#000000</CssParameter>
         <VendorOption name="autoWrap">100</VendorOption>
         <VendorOption name="maxDisplacement">50</VendorOption>
         <VendorOption name="repeat">1</VendorOption>
  • 2
    turn off tiling for your labels layer.
    – Ian Turton
    May 25, 2015 at 13:16
  • Thanks iant! I've changed in openlayers the TileWMS layer to ImageWMS and now displays correcly. This layer is not complex and renders fast, but in case I have a complex layer and I need tiling to improve performance, wich should be the proper way to display the labels? Maybe creating a point layer using polygon centroids? (Maybe I should edit my question...) May 27, 2015 at 7:29

1 Answer 1


You can use the following style.

    <ogc:Function name="centroid">

enter image description here

So the rendering of labels will be done on the centroid of the polygon.

  • Please add the code-like text as text, not picture. Apr 14, 2021 at 20:50
  • <se:Geometry> <ogc:Function name="centroid"> <ogc:PropertyName>geom</ogc:PropertyName> </ogc:Function> </se:Geometry>
    – ZhefengJin
    Apr 15, 2021 at 1:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.