Posts Tagged ‘Cartography’

Create Complex Line Style with GeoServer 2.x

GeoServer recently released 2.1.0. Among all the impressive improvements, I found line styling improvements most helpful for me. Prior to 2.x, there is nothing you can do but scratching your head when it comes to creating line style of alternating symbols, not to mention using custom smybol in the alternating symbols line style. 2.x is a dream comes true for me.

What I wanted to do:

Create a line style with alternating plus and minus sign and a fish symbol. Like this:

What I have:


To create a line style like that, I need a “+” symbol, a “-” symbol, and a fish symbol. For “+” symbol, I use well known name “Cross”. For “-” symbol, there is no well know name symbol so I use dash line instead to create the effect of “- – – “. and “-” symbol. For fish symbol, I have two source options: create my own or snapshot one from an existing image using any software that can clip an image. I also need to choose a graphic format to store the fish symbol. I decided to go with SVG instead of raster-based format such as JPEG and PNG because JPEG or PNG image might be resampled when you specify a pixel size of the image in the SLD that is different from the image’s original size. The resampling made the image look really ugly on map. Here is what I did to create the sytle:

  1. Create a fish symbol using Online Paint
  2. In SLD, set a FeatureTypeStyle with two LineSymbolizer. One line symbolizer with “+” and make it dashed graphic stroke. Set another line symbolizer with just stroke and make it dashed, which create a style of “- – – -“.  Combining this two symbolizers together gives me something look like “+-+-+-+-“
  3. Set another FeatureTypeStyle with  line symbolizer of external graphic. The external graphic is the fish symbol created in step 1. Make the line dashed so that the fish appears on the line every few pixels
  4. Apply the SLD to the line layer in GeoServer
  5. Played with the numbers in SLD (width, dasharray and dashoffset) for a while to get the best symbol size, line weight and interval between symbols

Here is the SLD code example: LineStyleSLD

Note: GeoServer 2.x allows user to create marks with True Type Font (TTF). But watch out if your testing operating system is different from your operational operating system. When you test in Windows environment, TTF is accessible. But then when you move the tested SLD to GeoServer running on Linux, the marks defined in TTF probably won’t show up because the TTF is not installed on Linux.