Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Ruby DSL for simpler SLD creation for styling maps

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 amanzi-sld.gemspec


A Ruby DSL for simpler SLD creation for styling maps

Map styles are often defined using SLD, or Style Layer Descriptor documents. These XML documents are very long, verbose and complex to maintain. Amanzi:SLD is a simpler DSL designed to generate SLD documents, but using a very much simpler syntax. Many common cases might be a single line only, while the simplest SLD is usually a dozen lines or more.

What is SLD?

There are great tutorials on the GeoServer wiki for SLD styling. Please take a look at GeoServer Styling

In brief, SLD is an XML syntax for specifying map layer styling. That is how to draw map layers. This includes simple things like what color and thickness a line should be as well as more complex topics like applying the style only to geometries matching certain filters and combining styles to create interesting effects. In principle it should be possible to create maps as good looking as one normally sees on sites like and

Why use Amanzi::SLD?

Well, The very simplest document in Amanzi::SLD is three lines long, while the same one in normal XML is almost 30 lines long. Consider:

require 'amanzi/sld'
sld ='Test')
sld.add_line_symbolizer :stroke => '#3050e0'

This will become the SLD document:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor xmlns:xlink=""
xmlns:ogc="" version="1.0.0"
                            <CssParameter name="stroke">#000000</CssParameter>
                            <CssParameter name="stroke-width">1</CssParameter>
                            <CssParameter name="stroke">#000000</CssParameter>
                            <CssParameter name="stroke-width">1</CssParameter>

How to get started?

The easiest way to get started would be to install the ruby gem using:

sudo gem install amanzi-sld

There is a chance that the gem is not yet available, in which case your next option is to download from source using:

git clone git://
cd amanzi-sld
rake install

Then you can create your ruby script with an appropriate content, for example:

require 'rubygems'
require 'amanzi/sld'

sld = 'My SLD Document'

  :stroke => '#004400',
  :stroke_width => 2,
  :geometry => 'LineString'

  :stroke => '#004400',
  :stroke_width => 2,
  :geometry => 'Polygon'

Advanced options

I will write this up when I get a chance. In the meantime I recommend looking at the more complex examples in the examples/ directory. Better yet, run them and see what the output looks like.

  • test.rb

    • This actually uses several redundant combinations of syntax to test the SLD as well as the underlying XML DSL on which it is based

    • This is also run by the normal rake tests, called from test/test_file.rb

    • The file test.sld is the expected output which the test will compare with

  • osm.rb

    • This advanced example works with the OpenStreetMap model imported into Neo4j Spatial, and then exposed as one or more layers to GeoServer or uDig

    • I know the colors are ugly, but it is just a demonstration of some of the options available, including labeling

    • Have a look at Neo4j Spatial for more on the data being styled. That project actually uses Amanzi:SLD for some of the default styles being built into the OSM DataStore.

  • osm_highway_shp.rb

    • This example works with the highway Shapefile generated from OSM data by CloudMade. See the CloudMade downloads

You can also read the test code in the test/ directory for information on some of the syntax options being tested.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.


Copyright © 2010 Craig Taverner. See LICENSE for details.

Something went wrong with that request. Please try again.