example.rst 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. .. _sld-extensions_composite-blend_example:
  2. Compositing and blending example
  3. --------------------------------
  4. Let's say we want to draw the ``topp:states`` layer so that the polygons are not filled with the population keyed
  5. colors, but only an inner border inside the polygon should appear, leaving the internal fully transparent.
  6. This is the destination:
  7. .. figure:: images/states.png
  8. topp:states layer
  9. Using alpha blending, this can be achieved by creating a mask around the state borders with a thick
  10. stroke, and then using a "destination-in" alpha compositing.
  11. This is the source (mask):
  12. .. figure:: images/states-border.png
  13. Layer mask
  14. The SLD will contain three FeatureTypeStyles. The first one would be the standard rules (states colored by population) and the last one will contain the label rules. The second (middle) one is where the blending will occur:
  15. .. code-block:: xml
  16. ...
  17. <FeatureTypeStyle>
  18. <!-- Usual states rules, skipped for brevity -->
  19. </FeatureTypeStyle>
  20. <FeatureTypeStyle>
  21. <Rule>
  22. <LineSymbolizer>
  23. <Stroke>
  24. <CssParameter name="stroke-width">10</CssParameter>
  25. <CssParameter name="stroke">#000000</CssParameter>
  26. </Stroke>
  27. </LineSymbolizer>
  28. </Rule>
  29. <VendorOption name="composite">destination-in</VendorOption>
  30. </FeatureTypeStyle>
  31. <FeatureTypeStyle>
  32. <!-- The label rules, skipped for brevity -->
  33. </FeatureTypeStyle>
  34. ...
  35. This is the result of the composition:
  36. .. figure:: images/states-border-composite.png
  37. Now, if for example someone makes a WMS call in which the another layer is drawn below this one, the result will look like this:
  38. .. figure:: images/ne-states-border-composite1.png
  39. This other background layer is hardly visible, because it has been cut by the mask. This shows the risks of using alpha compositing without care in a WMS setting.
  40. In order to achieve the desired result no matter how the client composes the request, the first FeatureTypeStyle that draws the polygons (the states themselves) needs to be set as a *compositing base*, ensuring the mask will only be applied to it.
  41. .. code-block:: xml
  42. <VendorOption name="composite-base">true</VendorOption>
  43. The result will look like the following (though a multiply blend was added to the base to ensure a nice
  44. visual transparency effect on the border lines):
  45. .. figure:: images/ne-states-border-composite2.jpg
  46. .. figure:: images/ne-states-border-composite3.jpg
  47. :download:`Download the final style <files/statesblend.sld>`
  48. .. note:: See the :ref:`full list of available modes <sld-extensions_composite-blend_modes>`.