Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling wms by request parameter

Tags:

geoserver

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), wms features
i wish geoserver to differrently style (blue dot) just one particular feature identified by a http-req-parameter sent with the wms request
enter image description here
keeping the others in the collection with default style
and avoiding an overlap of two wms:
enter image description here

like image 592
aleclofabbro Avatar asked Mar 14 '23 10:03

aleclofabbro


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.

like image 198
Ian Turton Avatar answered May 17 '23 16:05

Ian Turton


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

like image 38
Fbma Avatar answered May 17 '23 17:05

Fbma