Solved

How to use the XML filter in the WFS reader?


Userlevel 6
Badge +32
I'm having a hard time using the WFS XML filter. I surely built a working workbench before so I am sure this worked.

 

The only thing I want is adding a boundingbox in the WFS (2.0.0) request. I open the XML Filter setting and entered: 
 bbox=48187,407743,148934,408593
 The workbench fails. Log: 
 <ows:ExceptionReport version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://geodata.nationaalgeoregister.nl/schemas/ows/1.1.0/owsAll.xsd"><ows:Exception exceptionCode="XML getFeature request SAX parsing error" locator="org.vfny.geoserver.util.requests.readers.XmlRequestReader"><ows:ExceptionText>org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. Content is not allowed in prolog.</ows:ExceptionText></ows:Exception></ows:ExceptionReport>
 I look up the URL in the log and there it is: FME prefixed my filter with "FILTER=" 
 FILTER=bbox=48187,407743,148934,408593
 When I copy paste the url from the log to my browser, remove "FILTER=" and hit it, the requested features are returned.

 

 

I'm a little confused, I might be doing someting wrong but not sure what exactly. Anyone?
icon

Best answer by thijsknapen 3 March 2019, 13:10

View original

11 replies

Userlevel 4
Hi

 

 

I suspect the XML filter must actually be a valid XML block. Passing the BBOX values in the URI isn't the same thing as an XML filter function, so it behaves differently.

 

 

Would it be possible for you to modify the URL so that the BBOX values gets included there? I suspect this is also more efficient for the WFS server.

 

 

David
Userlevel 6
Badge +32
Heya David, that is exactly what I want to do but I do not know how. I can built and send the request with HTTPCaller but I do not know how to proces the response like the WFS reader does...
Userlevel 4
Badge +13
Hi,

 

You can try the following in the filter tag:

 

<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs">

 

<ogc:Overlaps>

 

<ogc:PropertyName>geom</ogc:PropertyName>

 

<gml:Polygon srsName="EPSG:28992">

 

<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>168649.196,446969.785671 168649.196,454456.416678 184608.68,454456.416678 184608.68,446969.785671 168649.196,446969.785671

 

</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>

 

</gml:Polygon>

 

</ogc:Overlaps>

 

</ogc:Filter>

 

 

Works on PDOK.
Userlevel 4
Badge +13
Hi again,

 

 

You can also just specify a bbox in the WFS reader parameters instead of the filter.
Userlevel 6
Badge +32
Heya Itay, the latter works indeed but then I need to enter the bbox coordinates by hand and being lazy and determined this should work...

 

 

The only simple thing I want is read features, determining boundingboxes, request the WFS with this boundingboxes and get points with attributes within the boudingboxes in return.

 

 

It should not be so hard but every time I want to do something the WFS reader can not do for me out of the box I tumble in this depressing XML / GML hole with allmost no positive results.
Userlevel 4
Badge +13
Hi Niels,

 

Pay close attention to the request result of the WFS reader when using the bbox filter, you can then use the request in a HTTPCaller adjusting the bbox coords to your calculated bboxses.

 

After that its a simple matter of using the GeometryReplacer to get the objects out of the responce XML.

 

 
Userlevel 6
Badge +32
Itay, the GeometryReplacer was my missing link in the HTTPCaller alternative. Thanks a million, learned a lot.
Badge +3

I have also struggled to find some proper documentation for the XML filter in the WFS reader.

For those interested, on the forum there are quite some related questions on this topic, e.g.:

Furthermore some more info on the topic of XML filters within WFS GetFeature requests, including some elegant examples can be found at:

 

From this search on the topic it seems like there are many ways to set up (a bounding box) XML filter for use within the WFS reader. E.g. The fourth link of the knowledge center hints towards the following XML filter to specify a bounding box:

<Filter>
   <Within>
      <PropertyName>geometry</PropertyName>
      <gml:Polygon>
         <gml:outerBoundaryIs>
            <gml:LinearRing>
               <gml:coordinates>89800,455000 99200,455000 99200,469000 89800,469000 89800,455000</gml:coordinates>
            </gml:LinearRing>
         </gml:outerBoundaryIs>
      </gml:Polygon>
   </Within>
</Filter>

On https://mapserver.org/ogc/filter_encoding.html the following example is given to specify a bounding box in an XML filter:

<Filter>
   <BBOX>
      <PropertyName>Name>NAME</PropertyName>
      <Box%20srsName='EPSG:42304'>  
         <coordinates>135.2239,34.4879 135.8578,34.8471</coordinates>
      </Box>
   </BBOX>
</Filter>

Finally the OGC Filter Encoding 2.0 specificaton also provide some nice examples of XML filter examples (starting from page 64 of that document, c.q. page 70 of the PDF). Example 4 of this document describes the following XML filter to specify a bounding box (where I omitted the namespace declarations):

<Filter>
   <BBOX>
      <ValueReference>Geometry</ValueReference>
      <Envelope srsName="urn:ogc:def:crs:EPSG::4326">
         <lowerCorner>13.0983 31.5899</lowerCorner>
         <upperCorner>35.5472 42.8143</upperCorner>
      </Envelope>
   </BBOX>
</Filter>

 

Extending from the BBOX examples, here are some initial observations from me on XML filters within the WFS reader:

  • It seems that a 'namespace declaration' is not always required for the 'nodes' within the XML filter expression of FME. I'm not sure if this is never needed.
  • Quite many of the examples on the forum for XML filters focus on 'attribute queries' that use the XML node 'PropertyName'. The first example from the OGC Filter Encoding 2.0 specificaton seems to use the XML node 'ValueReference' instead. In one of my workspaces I came across the situation that using the XML node 'PropertyName' didn't query out the required data, while using the ~similar (?) XML node 'ValueReference' did query out the desired data.

The example to the latter bullit was as follows. The following XML filter failed to query out the data:

<Filter>   
   <PropertyIsEqualTo>      
      <PropertyName>code</PropertyName>      
      <Literal>0505</Literal>   
   </PropertyIsEqualTo> 
</Filter>

While the following XML filter did query out the data.

<Filter>
   <PropertyIsEqualTo>
      <ValueReference>code</ValueReference>
      <Literal>0505</Literal>
   </PropertyIsEqualTo>
</Filter>

Please note that the first type of query did work for me in most other cases (I think the problem arises from the number starting with a 0). I'm also not sure if the XML node 'ValueReference' can be used for all WFS versions (i.e. it might be only valid for WFS version 2.0)

Badge +2

I have also struggled to find some proper documentation for the XML filter in the WFS reader.

For those interested, on the forum there are quite some related questions on this topic, e.g.:

Furthermore some more info on the topic of XML filters within WFS GetFeature requests, including some elegant examples can be found at:

 

From this search on the topic it seems like there are many ways to set up (a bounding box) XML filter for use within the WFS reader. E.g. The fourth link of the knowledge center hints towards the following XML filter to specify a bounding box:

<Filter>
   <Within>
      <PropertyName>geometry</PropertyName>
      <gml:Polygon>
         <gml:outerBoundaryIs>
            <gml:LinearRing>
               <gml:coordinates>89800,455000 99200,455000 99200,469000 89800,469000 89800,455000</gml:coordinates>
            </gml:LinearRing>
         </gml:outerBoundaryIs>
      </gml:Polygon>
   </Within>
</Filter>

On https://mapserver.org/ogc/filter_encoding.html the following example is given to specify a bounding box in an XML filter:

<Filter>
   <BBOX>
      <PropertyName>Name>NAME</PropertyName>
      <Box%20srsName='EPSG:42304'>  
         <coordinates>135.2239,34.4879 135.8578,34.8471</coordinates>
      </Box>
   </BBOX>
</Filter>

Finally the OGC Filter Encoding 2.0 specificaton also provide some nice examples of XML filter examples (starting from page 64 of that document, c.q. page 70 of the PDF). Example 4 of this document describes the following XML filter to specify a bounding box (where I omitted the namespace declarations):

<Filter>
   <BBOX>
      <ValueReference>Geometry</ValueReference>
      <Envelope srsName="urn:ogc:def:crs:EPSG::4326">
         <lowerCorner>13.0983 31.5899</lowerCorner>
         <upperCorner>35.5472 42.8143</upperCorner>
      </Envelope>
   </BBOX>
</Filter>

 

Extending from the BBOX examples, here are some initial observations from me on XML filters within the WFS reader:

  • It seems that a 'namespace declaration' is not always required for the 'nodes' within the XML filter expression of FME. I'm not sure if this is never needed.
  • Quite many of the examples on the forum for XML filters focus on 'attribute queries' that use the XML node 'PropertyName'. The first example from the OGC Filter Encoding 2.0 specificaton seems to use the XML node 'ValueReference' instead. In one of my workspaces I came across the situation that using the XML node 'PropertyName' didn't query out the required data, while using the ~similar (?) XML node 'ValueReference' did query out the desired data.

The example to the latter bullit was as follows. The following XML filter failed to query out the data:

<Filter>   
   <PropertyIsEqualTo>      
      <PropertyName>code</PropertyName>      
      <Literal>0505</Literal>   
   </PropertyIsEqualTo> 
</Filter>

While the following XML filter did query out the data.

<Filter>
   <PropertyIsEqualTo>
      <ValueReference>code</ValueReference>
      <Literal>0505</Literal>
   </PropertyIsEqualTo>
</Filter>

Please note that the first type of query did work for me in most other cases (I think the problem arises from the number starting with a 0). I'm also not sure if the XML node 'ValueReference' can be used for all WFS versions (i.e. it might be only valid for WFS version 2.0)

@thijsknapen Great info, thanks

I have also struggled to find some proper documentation for the XML filter in the WFS reader.

For those interested, on the forum there are quite some related questions on this topic, e.g.:

Furthermore some more info on the topic of XML filters within WFS GetFeature requests, including some elegant examples can be found at:

 

From this search on the topic it seems like there are many ways to set up (a bounding box) XML filter for use within the WFS reader. E.g. The fourth link of the knowledge center hints towards the following XML filter to specify a bounding box:

<Filter>
   <Within>
      <PropertyName>geometry</PropertyName>
      <gml:Polygon>
         <gml:outerBoundaryIs>
            <gml:LinearRing>
               <gml:coordinates>89800,455000 99200,455000 99200,469000 89800,469000 89800,455000</gml:coordinates>
            </gml:LinearRing>
         </gml:outerBoundaryIs>
      </gml:Polygon>
   </Within>
</Filter>

On https://mapserver.org/ogc/filter_encoding.html the following example is given to specify a bounding box in an XML filter:

<Filter>
   <BBOX>
      <PropertyName>Name>NAME</PropertyName>
      <Box%20srsName='EPSG:42304'>  
         <coordinates>135.2239,34.4879 135.8578,34.8471</coordinates>
      </Box>
   </BBOX>
</Filter>

Finally the OGC Filter Encoding 2.0 specificaton also provide some nice examples of XML filter examples (starting from page 64 of that document, c.q. page 70 of the PDF). Example 4 of this document describes the following XML filter to specify a bounding box (where I omitted the namespace declarations):

<Filter>
   <BBOX>
      <ValueReference>Geometry</ValueReference>
      <Envelope srsName="urn:ogc:def:crs:EPSG::4326">
         <lowerCorner>13.0983 31.5899</lowerCorner>
         <upperCorner>35.5472 42.8143</upperCorner>
      </Envelope>
   </BBOX>
</Filter>

 

Extending from the BBOX examples, here are some initial observations from me on XML filters within the WFS reader:

  • It seems that a 'namespace declaration' is not always required for the 'nodes' within the XML filter expression of FME. I'm not sure if this is never needed.
  • Quite many of the examples on the forum for XML filters focus on 'attribute queries' that use the XML node 'PropertyName'. The first example from the OGC Filter Encoding 2.0 specificaton seems to use the XML node 'ValueReference' instead. In one of my workspaces I came across the situation that using the XML node 'PropertyName' didn't query out the required data, while using the ~similar (?) XML node 'ValueReference' did query out the desired data.

The example to the latter bullit was as follows. The following XML filter failed to query out the data:

<Filter>   
   <PropertyIsEqualTo>      
      <PropertyName>code</PropertyName>      
      <Literal>0505</Literal>   
   </PropertyIsEqualTo> 
</Filter>

While the following XML filter did query out the data.

<Filter>
   <PropertyIsEqualTo>
      <ValueReference>code</ValueReference>
      <Literal>0505</Literal>
   </PropertyIsEqualTo>
</Filter>

Please note that the first type of query did work for me in most other cases (I think the problem arises from the number starting with a 0). I'm also not sure if the XML node 'ValueReference' can be used for all WFS versions (i.e. it might be only valid for WFS version 2.0)

Hi,

 

Thanks for the links. I am having problem understanding the lower corner and upper corner coordinates. Could you please help me how to identify them pictorially? I am using EPSG 3857.

 

Much appreciated for your help

Badge +20

Hi,

 

Thanks for the links. I am having problem understanding the lower corner and upper corner coordinates. Could you please help me how to identify them pictorially? I am using EPSG 3857.

 

Much appreciated for your help

Just use BoundsExtractor.

Lower left corner is _xmin, _ymin

Upper right corner is _xmax, _ymax

LL UR

Reply