label-obstacles.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. .. _label_obstacles:
  2. Label Obstacles
  3. ===============
  4. GeoServer implements an algorithm for label conflict
  5. resolution, to prevent labels from overlapping one another.
  6. By default this algorithm only considers conflicts with other labels.
  7. This can result in labels
  8. overlapping other symbolizers, which may produce an undesirable effect.
  9. .. cssclass:: no-border
  10. .. figure:: images/label-obstacle1.jpg
  11. .. figure:: images/label-obstacle2.jpg
  12. GeoServer supports a vendor option called ``labelObstacle`` that allows
  13. marking a symbolizer as an obstacle.
  14. This tells the labeller to avoid rendering labels that overlap it.
  15. .. warning::
  16. Beware of marking a line or poly symbolizer as a label obstacle. The label conflict resolving routine is
  17. based on the bounding box so marking as a label obstacle will result in no label overlapping not only
  18. the geometry itself, but its bounding box as well.
  19. .. code-block:: xml
  20. <?xml version="1.0" encoding="ISO-8859-1"?>
  21. <StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
  22. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  23. <NamedLayer>
  24. <UserStyle>
  25. <FeatureTypeStyle>
  26. <Rule>
  27. <PointSymbolizer>
  28. <Graphic>
  29. <ExternalGraphic>
  30. <OnlineResource
  31. xlink:type="simple"
  32. xlink:href="smileyface.png" />
  33. <Format>image/png</Format>
  34. </ExternalGraphic>
  35. <Size>32</Size>
  36. </Graphic>
  37. <VendorOption name="labelObstacle">true</VendorOption>
  38. </PointSymbolizer>
  39. </Rule>
  40. </FeatureTypeStyle>
  41. </UserStyle>
  42. </NamedLayer>
  43. </StyledLayerDescriptor>
  44. .. cssclass:: no-border
  45. .. figure:: images/obs-externalGraphic1.png
  46. .. figure:: images/obs-externalGraphic2.png
  47. Applying the obstacle to a regular point style:
  48. .. code-block:: xml
  49. <PointSymbolizer>
  50. <Graphic>
  51. <ExternalGraphic>
  52. <OnlineResource
  53. xlink:type="simple"
  54. xlink:href="smileyface.png" />
  55. <Format>image/png</Format>
  56. </ExternalGraphic>
  57. <Size>32</Size>
  58. </Graphic>
  59. <VendorOption name="labelObstacle">true</VendorOption>
  60. </PointSymbolizer>
  61. .. cssclass:: no-border
  62. .. figure:: images/obs-mark1.png
  63. .. figure:: images/obs-mark2.png
  64. Applying the obstacle to line/polygon style:
  65. .. cssclass:: no-border
  66. .. figure:: images/obs-line1.png
  67. .. figure:: images/obs-line2.png
  68. .. figure:: images/obs-poly1.png
  69. .. figure:: images/obs-poly2.png