4

I ran into this problem that is (almost) nowhere on the internet and thought I'd share the solution. GeoServer supports parametrized SQL views for Web Feature Services (WFS) but the documentation leaves out a crucial fact (in fact its clear they cut and pasted the docs for the same page for WMS), since in a WFS all the requests are GET requests, they tell you to simply tack on to the query string a key value string of the form:

viewparams=keyOne:valueOne;keyTwo:valueTwo;

However in the GetFeature request, we have a POST request with an XML based payload and no obvious way to include the viewparams string. How does one do that?

1 Answer 1

6

Here is a typical request payload for a GetFeature with the viewparams included in the xml:

<?xml version='1.0' encoding='utf-8'?>
<GetFeature 
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
 xmlns:gml='http://www.opengis.net/gml'
 xmlns:ogc='http://www.opengis.net/ogc'
 wfs:viewParams='keyOne:ValueOne;keyTwo:ValueTwo'
 xmlns:wfs='http://www.opengis.net/wfs'
 xmlns='http://www.opengis.net/wfs'
 xmlns:ccc='http://[URL]:8080/zipcodes'
 version='1.0.0' service='WFS' maxFeatures='100'>
 <wfs:Query typeName='ccc:myLayer' srsName='EPSG:4326'>
  <ogc:Filter xmlns:ogc='http://www.opengis.net/ogc'>
   <ogc:BBOX>
    <ogc:PropertyName>ccc:geom</ogc:PropertyName>
    <gml:Box srsName='EPSG:4326'>
      <gml:coordinates>-126.24227121874098,25.286303720463525 -70.91512278125568,51.972617139892904</gml:coordinates>
    </gml:Box>
   </ogc:BBOX>
  </ogc:Filter>
 </wfs:Query>
</GetFeature>

In short, add a wfs:viewParams attribute to the main GetFeature xml element with the same key value string as above.

1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.