in general:
Is it possible to differently style some of the wms features from a single wms query based on the cql filter, or other parameter?
in particular:
on a wms query, returning the raster of a collection of features (i.e. points styled as red dots),
i wish geoserver to differrently style (blue dot) just one particular feature identified by a http-req-parameter sent with the wms request
keeping the others in the collection with default style
and avoiding an overlap of two wms:

- 1,635
- 1
- 18
- 35
-
As in [http://docs.geoserver.org/stable/en/user/styling/sld-working.html]: "An SLD document can be provided directly in a WMS GetMap GET request using the SLD_BODY=style parameter. The SLD XML must be URL-encoded.", would it be a valid scenario for you, creating the SLD on the fly per request with the appropiate filter? – Fbma Oct 20 '15 at 11:58
-
@Fbma i think that would globally restyle the layer, i edited my Q as it might be unclear.. – aleclofabbro Oct 20 '15 at 15:50
-
ok i see.. the overlapping can be avoided by setting the 1st filter as the negation of the 2nd ;) – aleclofabbro Oct 22 '15 at 09:45
2 Answers
A quicker (and probably easier) way than @Fmba's suggestion is to request the layer twice, once with the default color and a second time with a filter and a highlight style. You could either do this in one request or make two requests so that the browser can cache the default layer and only refetch the highlights.
For the first request it would look something like:
http://....../wms?service=wms&.....&layers=dots,dots&styles=,highlight&cql_filter=INCLUDE;INTERSECT(the_geom,%20POINT%20(-74.817265%2040.5296504))
This requests the layer (dots) twice, once with the default style (or you could use a named style here too) and then with the highlight style. Finally you must supply two filters (the first is just true to return everything).
while in the second you would just add another layer as usual.

- 10,018
- 1
- 28
- 47
-
-
-
@iant : examples in my original Q might be misleading, cause the «selected» style whas same shape as «unselected», does it work for different shapes or it just overlaps two wms? [edited the Q to further clarify] – aleclofabbro Oct 22 '15 at 09:04
-
As I understand, you can avoid the graphical overlapping simply specifying in the first CQL filter the right condition, instead of setting it to 'true'. So: first filter to select features that are not the ones you want, and second filter for the feature that you want to highlight. – Fbma Oct 22 '15 at 09:25
-
@Fbma is correct, you would need to exclude the highlighted item from the first map if they are different shapes, I usually use this for polygons so it isn't an issue. – Ian Turton Oct 22 '15 at 09:26
-
btw, seems the `cql_filter=true` is not allowed by geoserver.. it responds with `Could not parse CQL filter list. Encountered "true ;" at line 1, column 1. Was expecting one of:... .... ... Parsing : true;name='gufo'` .. this `cql_filter=1=1;...` works instead – aleclofabbro Oct 22 '15 at 10:05
-
You can use both filters and variable substitution for this. Your SLD could be something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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">
<!-- a Named Layer is the basic building block of an SLD document -->
<NamedLayer>
<Name>default_point</Name>
<UserStyle>
<!-- Styles can have names, titles and abstracts -->
<Title>Default Point</Title>
<Abstract>A sample style that draws a point</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>rule1</Name>
<Title>Red Square</Title>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>square</WellKnownName>
<Fill>
<CssParameter name="fill">#FF0000</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</PointSymbolizer>
</Rule>
<Rule>
<Name>rule2</Name>
<Title>Blue Square</Title>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>name</ogc:PropertyName>
<ogc:Function name="env">
<ogc:Literal>element</ogc:Literal>
</ogc:Function>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>square</WellKnownName>
<Fill>
<CssParameter name="fill">#0000FF</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
See that we are using a parameter called 'element' (as we defined in the SLD) in the 'env' parameter (at the end of the request), wich you can assign a value in the wms request, so only the feature with a value of 'name_yo_want_to_filter' for the attribute 'name' would be rendered as blue, like this:
http://your_geoserver/wms?LAYERS=your_layer&STYLES=&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG%3A25830&BBOX=177329.45520721,4198063.2254456,177681.24924735,4198495.164411&WIDTH=417&HEIGHT=512&env=element:name_yo_want_to_filter
Bear in mind that 'fid' would not be a valid parameter as it is usually hidden, so geoserver wont accept a 'PropertyIsEqualTo' filter of it.
Ref: http://docs.geoserver.org/latest/en/user/styling/sld-extensions/substitution.html Ref: http://docs.geoserver.org/latest/en/user/styling/sld-reference/filters.html

- 126
- 4
-
well, @iant 's aswer is truly neater for my specific issue, but +1 for your very useful tip too! – aleclofabbro Oct 22 '15 at 07:29