I would like to show overlapping polygons on a single layer.

The polygons are coloured based on a property and labelled according to another property. The problem is then twofold:

  • The polygons are rendered in random order in tiles where they overlap, resulting in some small ones to "disappear" under the larger ones (e.g. cities "under" regions), while I would like them to be rendered according to a given property (I was thinking about using Priority but it is available only for TextSymbolizer in geoserver).
  • The labels of larger polygons are shown "on top" of smaller polygons, while I would like to have them drawn ( repeated ) only at areas where the two (or more) polygons do not overlap. E.g. State names only to be shown where no other regional surface is being drawn (even if this might result in State names not being shown at all).

Is there a proper way of doing it?

  • 1
    polygons are actually drawn in the order they come out of the datastore so depending on how you have stored them you could apply a sort.
    – Ian Turton
    Aug 27, 2015 at 9:07
  • Indeed a sort affects the drawing order, which solves the first issue! On postgis a view as "select * from unsorted_table order by sortfield asc;" gives properly drawn polygons.
    – a1an
    Aug 31, 2015 at 12:55
  • The second one is unsolvable with out assigning specific spots to draw the labels at as the labeling algorithm doesn't understand about overlaps.
    – Ian Turton
    Aug 31, 2015 at 12:56
  • I see. Knowing the drawing order I could do a second step by replacing the "simple" polygons P with the difference P - ( union of polygons "on top of" P). Would that work or would the label still be placed at the centroid of the outer polygon?
    – a1an
    Aug 31, 2015 at 13:06
  • you'd might be able to use a geometry transform to get the difference polygon and generate it's centroid to position the label but it would be slow at render time. an extension of <sld:Geometry> <ogc:Function name="centroid"> <ogc:PropertyName>geom</ogc:PropertyName> </ogc:Function> </sld:Geometry>
    – Ian Turton
    Aug 31, 2015 at 13:15

1 Answer 1


As @iant pointed out, what appeared to be random order is the order in which the back end delivers the polygons to geoserver. Sorting them according to a property reflecting the desired display order is the correct way to solve it.

Unfortunately the labelling issue cannot be solved trivially on server side and on client side the most promising solution is to compute labelling points using WFS to retrieve involved geometries (but indeed slow).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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