SLD Cookbook

Styling map layers in GeoServer can be challenging. While there are some ways to craft map layers without ever needing to look at Styled Layer Descriptor (SLD) code, there are some who don’t want an intermediary and want to code with SLD directly. For those, there are few options:

1. Read the OGC SLD 1.0 specification. At 100+ pages, it can be a bit dense.
2. Read the SLD schema. Because, really, who doesn’t love interpreting schemas?

Failing those, the would-be map stylist is usually out of luck, needing to eke out an understanding of styling by asking on mailing lists and doing web searches.

When I was learning SLD, I wanted simple examples that I could understand and edit. I wanted screenshots. I wanted to know which line of code did what. I wanted to look up styles as if they were in a recipe book. But this type of reference didn’t exist at the time.

The SLD Cookbook is that reference. It is a “practical reference” to show how map styling works. It is not designed to be exhaustive, and it won’t tell you about every possible edge case. But it also has no SLDs that are hundreds of lines long, a strong hurdle to comprehension.

Want to know how to style a simple point? Look at the example, download the SLD (and the shapefile that generated the screenshot too, if you’d like), and read the details. See which line of code accomplishes what, so if you want to make the points blue instead of red, you’ll know what line to change (line 8 in this case). Want to see how to make a style where lines are styled differently by data attributes? Or by zoom level? Refer as necessary. Even those experienced with SLD may find the examples useful.

There are a few examples mixed in that leverage extensions to GeoServer/GeoTools (polygon fill hatching, labels that follow lines) but for the most part, the examples are perfectly valid according to the SLD 1.0 specification.

I’m sure that more examples can and will be added in time. I’ve already received some very good feedback from others, and some styles will likely be optimized. But every example, every screenshot, and every SLD was tested in the most recent version of GeoServer.

So take a look, and get styling! I hope you enjoy. Special thanks goes out to Geonovum, who funded this project. I personally appreciate it.


  1. Posted April 9, 2010 at 3:48 pm | Permalink

    Thanks to both you and the sponsor. This is a great reference and nice and simple.

  2. Posted May 18, 2010 at 1:57 pm | Permalink

    It is great that the Cookbook now also shows examples for lines and polygons!
    I would like to see a code sample using PerpendicularOffset for lines.

  3. Posted May 18, 2010 at 1:59 pm | Permalink

    It is great that the Coookbook now shows examples for lines and polygons!
    I would like to see a code sample for PerpendicularOffset used for lines or polygons(-strokes).

Post a Comment

You must be logged in to post a comment.

Download GeoServer