Skip to content

Instantly share code, notes, and snippets.

@mdiener21
Created July 3, 2014 21:23
Show Gist options
  • Save mdiener21/30c499ba9098ee60454b to your computer and use it in GitHub Desktop.
Save mdiener21/30c499ba9098ee60454b to your computer and use it in GitHub Desktop.
Geoserver SLD variable substitution attribute based color assignment in wms call URL . Simpley add &env=a:000066;b:6666ff to the end of your wms call and you will have dynamically changed the zone "a" color to 000066 and zone "b" color to 6666ff
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
<NamedLayer>
<Name>Study Zones</Name>
<UserStyle>
<Name>Study Zones</Name>
<Title>Default zone style</Title>
<Abstract>Study Zone style</Abstract>
<FeatureTypeStyle>
<Name>Study Zones</Name>
<Rule>
<Title>Zone A</Title>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>zone_name</ogc:PropertyName>
<ogc:Literal>a</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<MaxScaleDenominator>50000</MaxScaleDenominator>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">
#<ogc:Function name="env">
<ogc:Literal>a</ogc:Literal>
<ogc:Literal>FF0000</ogc:Literal>
</ogc:Function>
</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
<Rule>
<Title>Zone A</Title>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>zone_name</ogc:PropertyName>
<ogc:Literal>b</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<MaxScaleDenominator>50000</MaxScaleDenominator>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">
#<ogc:Function name="env">
<ogc:Literal>b</ogc:Literal>
<ogc:Literal>0000ff</ogc:Literal>
</ogc:Function>
</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment