Fun with Styled Layer Descriptors
Some examples of working with SLD's.
Background Information
For a full overview of Styled Layer Descriptors, see the OGC web page and implementation specification. The specification is an excellent reference document and contains many example SLD's showing filtering and text formatting.
Examples
Below are examples of SLD's that are used in various GeoWS services, showing some simple SLD usage.
Labeled stations:
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>Station Point</Name>
<UserStyle>
<Title>A style for IRIS stations</Title>
<Abstract>Style to display stations</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>Rule 1</Name>
<Title>Station Rule</Title>
<Abstract>Triangle with label</Abstract>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>triangle</WellKnownName>
<Fill>
<CssParameter name="fill">#000080</CssParameter>
</Fill>
</Mark>
<Size>5.0</Size>
</Graphic>
</PointSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>station</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Arial</CssParameter>
<CssParameter name="font-style">bold</CssParameter>
<CssParameter name="font-size">10</CssParameter>
</Font>
<!-- move label a little to the left so that its 'beside' the dot-->
<LabelPlacement>
<PointPlacement>
<Displacement>
<DisplacementX> 5 </DisplacementX>
<DisplacementY> 0 </DisplacementY>
</Displacement>
</PointPlacement>
</LabelPlacement>
<Fill>
<CssParameter name="fill">#000080</CssParameter>
</Fill>
<VendorOption name="group">no</VendorOption>
</TextSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Graphic size changes with attribute size:
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>Event Point</Name>
<UserStyle>
<Title>A style for IRIS seismic events</Title>
<Abstract>A style with varying point size depending on magniutde</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>Magnitude greater than 7.0</Name>
<Title>Large Red Point</Title>
<Abstract>A large red point for events greater than 7.0</Abstract>
<ogc:Filter>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>Magnitude</ogc:PropertyName>
<ogc:Literal>7.0</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#ff0000</CssParameter>
</Fill>
</Mark>
<Size>10.0</Size>
</Graphic>
</PointSymbolizer>
</Rule>
<Rule>
<Name>Magnitude between 6.0 and 7.0</Name>
<Title>Medium Orange-red Point</Title>
<Abstract>A medium orange-red point for events between 6.0 and 7.0</Abstract>
<ogc:Filter>
<ogc:PropertyIsBetween>
<ogc:PropertyName>Magnitude</ogc:PropertyName>
<ogc:LowerBoundary><ogc:Literal>6.0</ogc:Literal></ogc:LowerBoundary>
<ogc:UpperBoundary><ogc:Literal>7.0</ogc:Literal></ogc:UpperBoundary>
</ogc:PropertyIsBetween>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#ff5500</CssParameter>
</Fill>
</Mark>
<Size>8.0</Size>
</Graphic>
</PointSymbolizer>
</Rule>
<Rule>
<Name>Magnitude between 5.0 and 6.0</Name>
<Title>Small Orange Point</Title>
<Abstract>A small orange point for events between 5.0 and 6.0</Abstract>
<ogc:Filter>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>Magnitude</ogc:PropertyName>
<ogc:Literal>6.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#ff8c00</CssParameter>
</Fill>
</Mark>
<Size>5.0</Size>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>