In Geoserver, a have a SLD style with a rule that looks like this
<Rule>
<ogc:Filter>
<ogc:PropertyIsGreaterThan>
<ogc:Function name="env">
<ogc:PropertyName>
property
</ogc:PropertyName>
</ogc:Function>
<ogc:Function name="env">
<ogc:Literal>value1</ogc:Literal>
<ogc:Literal>0</ogc:Literal>
</ogc:Function>
</ogc:PropertyIsGreaterThan>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">
#ff0000
</CssParameter>
<CssParameter name="fill-opacity">
0.5
</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
In the WMS request, i send an env parameter, specifing the property
and the value1
parameters for dynamic sld substitution. The property
parameter gets a value of an attribute name that exists on the layer I want to display the style with.
My solution won't work. I get an exception, saying:
The requested style cannot be used with this layer. The style
specifies an attribute property and the layer is: …
Is there a way to set the attribute name dynamically via sld substitution in Geoserver? And if yes, how can I achive that?
I am using Geoserver 2.7.2
Btw. this works:
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>
Einwohner
</ogc:PropertyName>
<ogc:Function name="env">
<ogc:Literal>value1</ogc:Literal>
<ogc:Literal>0</ogc:Literal>
</ogc:Function>
</ogc:PropertyIsGreaterThan>
Best Answer
I could not work this out. The feature of dynamically setting property names via env variables seems not to be supported at this moment.
I ended up with a different solution now (using the Geoserver REST API for styles) and I am quite happy with it.
Here is what I did: based on what the user enters on the GUI, I manually wrote sld (as a complete string). Then, I uploaded this string to the style REST endpoint of Geoserver, setting the correct content-header, as described here: http://docs.geoserver.org/2.7.1/user/rest/api/styles.html
Every style is getting a unique identifier. Before uploading a style, I try to download it via GET to see if it exists. If I get a 404, I do a POST to upload a new style. Otherwise, I upload my string with a PUT to modify the existing style. Once a style has been uploaded, I use the style Id in WMS GetMap requests.