Geoserver SLD variable substitution based on attribute

SLD (Styled Layer Description) is a beast of XML rules, filters and other stuff with tons of power.

The question at hand is how do I pass a color value to a certain attribute value in a WMS call to Geoserver? The documentation to read is http://docs.geoserver.org/latest/en/user/styling/sld/extensions/substitution.html


lets start with the SLD

Here there are two rules, the first rule sets the default color for the column "zone_name" with the value equal to "a" to a default color of "FF0000".  The second rule is defined to set the color for the column "zone_name" that is equal to value "b" and sets the default color to "0000ff".

Now for the dynamic part.  In your WMS call simply add this to the url

&env=a:6666ff;b:ff6666

this means  set the "a" zone to the new color "6666ff  and set the "b" zone to new color "ff6666" when the wms call is made.

Now you can do whatever backend magic your heart desires to dynamically create a WMS call with these 2 parameters.

cheers
Michael

Comments

Popular Posts