When you’re styling vector data, you may have a need for thematic styling. With thematic styling, you base styling options such as the size of an icon or the fill color of an area on an object property. For example, you want to show big cities with larger icons than small cities.
Using OGC SLD/SE styling, you can achieve property-based styling through rules. A rule has an optional filter and a scale range that defines when to apply the rule and its styling options.
This example of a rule defines that a particular point styling is only applicable when a property POPULATION has a value greater than 10000:
<Rule>
<ogc:Filter>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>POPULATION</ogc:PropertyName>
<ogc:Literal>100000</ogc:Literal>
</ogc:PropertyIsGreaterThan>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<Fill><SvgParameter name="fill">#FF0000</SvgParameter>
</Mark>
</Graphic>
</PointSymbolizer>
</Rule>
Although this is a flexible approach to define thematic styling, you may end up with large style files if you have lots of conditions. For example, if you want to style each state in the US with a distinct fill color, you need a styling rule per state.
An alternative, more concise approach is to rely on a function. This example illustrates how you can use a function to determine the fill color based on the name of a US state, in a single rule:
<?xml version='1.0' encoding='UTF-8'?>
<FeatureTypeStyle xmlns="http://www.opengis.net/se"
version="1.1.0">
<Name>Thematic style</Name>
<Description>
<Title>Thematic US states style</Title>
<Abstract>Renders the US states with a black outline and a different fill color per state.</Abstract>
</Description>
<Rule>
<PolygonSymbolizer>
<Fill>
<SvgParameter name="fill">
<ogc:Function name="Recode">
<ogc:PropertyName>STATE_NAME</ogc:PropertyName>
<ogc:Literal>Washington</ogc:Literal>
<ogc:Literal>#FF0000</ogc:Literal>
<ogc:Literal>New York</ogc:Literal>
<ogc:Literal>#00FF00</ogc:Literal>
...
</ogc:Function>
</SvgParameter>
</Fill>
<Stroke>
<SvgParameter name="stroke-opacity">
<ogc:Literal>1.0</ogc:Literal>
</SvgParameter>
<SvgParameter name="stroke-width">
<ogc:Literal>2</ogc:Literal>
</SvgParameter>
<SvgParameter name="stroke">
<ogc:Literal>#000000</ogc:Literal>
</SvgParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
The example uses the OGC Recode
function, which you can use to map property values to other values - such as colors and sizes.
This function is one of the built-in functions described in TLcdOGCVendorSpecificFunctions
. You can also
plug in your own functions. For more information, see this article.