📁
Filter Expressions in FME
  • Introduction
  • Credits
  • Working Environment
  • GetCapabilities
  • 1st Filter
  • The Formula
  • Bulk Processing
  • Comparison Operators
  • Spatial Operators
  • Logical Operators
  • DefaultCRS vs OtherCRS
  • Outlook: WFS 3.0
  • Resources
  • Ideas for improvement
  • Expression Library
Powered by GitBook
On this page
  • BBOX
  • Within
  • DWithin
  • Spatial Filtering using more than a rectangle

Spatial Operators

What really happens under the hood

PreviousComparison OperatorsNextLogical Operators

Last updated 26 days ago

We will have a look at some Spatial Operators now. Remember what we saw in GetCapabilities:

<fes:SpatialOperators>
   <fes:SpatialOperator name="BBOX"/>
   <fes:SpatialOperator name="Equals"/>
   <fes:SpatialOperator name="Disjoint"/>
   <fes:SpatialOperator name="Intersects"/>
   <fes:SpatialOperator name="Touches"/>
   <fes:SpatialOperator name="Crosses"/>
   <fes:SpatialOperator name="Within"/>
   <fes:SpatialOperator name="Contains"/>
   <fes:SpatialOperator name="Overlaps"/>
   <fes:SpatialOperator name="Beyond"/>
   <fes:SpatialOperator name="DWithin"/>
</fes:SpatialOperators>

As we are using the FeatureReader, you may ask yourself: FeatureReader comes with predefined Spatial Filters, so why should I look into Spatial Filter Expressions?

The answer is: Yes, the Spatial Filters listed above are working in most cases, but they don't use XML Filter Expressions!

Let's consult our best friend the Translation Log. To do so, you may use the following lightweight Workbench.

Parameter
Value

WFS URL

Version

2.0

Features Types

Flurstueck (cadastral parcel)

Max Features

leave blank

Select a Spatial Filter of your choice (except OGC-Disjoint), run the Workbench, switch to Translation Log and look for the already known

<WFS> GetFeature URL:

You'll find a really long URL like this

And the most interesting thing is this

&BBOX=xmin,ymin,xmax,ymax,urn:ogc:def:crs:EPSG::25832&

According to OGC WFS specification, you may also pass a Bounding Box (BBOX) as URL Parameter (see ampersands &) to the WFS service.

Spatial Filter
Request
Notice

Bounding Boxes OGC-Intersect

BBOX as URL Parameter

Initiator OGC-Intersects Result

BBOX as URL Parameter

Initiator OGC-Contains Result

BBOX as URL Parameter

Initiator OGC-Crosses Result

BBOX as URL Parameter

Initiator is OGC-Disjoint from Result

No filter

get's max. number of features and may run into a timeout

Initiator OCG-Equals Result

BBOX as URL Parameter

Initiator OGC-Overlaps Result

BBOX as URL Parameter

Initiator OGC-Touches Result

BBOX as URL Parameter

Initiator is OGC-Within Result

BBOX as URL Parameter

What does this mean?

This means, that the FeatureReader sends a BBOX to the WFS and does the spatial filtering within this BBOX locally, which means inside FME itself (client-side).

That's generally ok, but as we are dealing with Filter Expressions where the WFS service does the filtering server-side, we will have a look, what's possible using XML Filter Expressions.

Let's return to our already known INSPIRE cadastral parcel WFS.

Parameter
Value

WFS URL

Version

2.0

Features Types

CadastralParcel

Max Features

leave blank

xmlns

gml="http://www.opengis.net/gml/3.2" cp="http://inspire.ec.europa.eu/schemas/cp/4.0"

BBOX

The BBOX is the most powerful filter. It's a real swiss army knife! Not without good reason the FeatureReader uses a Bounding Box (BBOX) for spatial filtering.

You may paste the following Filter Expression into a WFS Reader

<fes:Filter
	xmlns:fes="http://www.opengis.net/fes/2.0"
	xmlns:gml="http://www.opengis.net/gml/3.2">
  <fes:BBOX>
        <gml:Envelope srsName="urn:ogc:def:crs:EPSG::25832">
          <gml:lowerCorner>367441.62 5620100.532</gml:lowerCorner>
          <gml:upperCorner>367619.15 5620254.767</gml:upperCorner>
       </gml:Envelope>
   </fes:BBOX>
</fes:Filter>

but we'll skip that step.

Utilize Creator instead to build a BBOX using the coordinates shown above.

Set the Coordinate System to EPSG:25832 and fetch the Coordinates (xmin, ymin, xmax, ymax) with BoundsExtractor.

Color the outline of the BBOX (FeatureColorSetter) and connect the Inspector.

Insert a FeatureReader, configure the WFS connection as shown above and paste the following Filter Expression

<fes:Filter
	xmlns:fes="http://www.opengis.net/fes/2.0"
	xmlns:gml="http://www.opengis.net/gml/3.2">
  <fes:BBOX>
        <gml:Envelope srsName="urn:ogc:def:crs:EPSG::25832">
          <gml:lowerCorner>@Value(xmin) @Value(ymin)</gml:lowerCorner>
          <gml:upperCorner>@Value(xmax) @Value(ymax)</gml:upperCorner>
       </gml:Envelope>
   </fes:BBOX>
</fes:Filter>

As you can see, it get's the BBOX corner coordinates dynamically as well.

Connect the FeatureReader also with the Inspector and run the Workbench.

The BBOX Filter selects all features, that are touched by the BBOX on the WFS server (server-side). So far so good.

But what's the magic?

But you've postal addresses instead and you are able to geocode them, i.e. you know the xy-coordinates of the address point, e.g.

Address:             Platz der Vereinten Nationen 2, 53113 Bonn
XY-Coords (UTM32N):  367591.0 5620196.0   

If so

Tadaa: what's the result?

We got our already known cadastral parcel 05430202600946______, this time using a Spatial Filter Expression.

As you can replace nearly any geometry by its BBOX, now you know how to use it, either by a

  • BBOX Filter Expression or

  • FMEs built-in BBOX Filter

For the sake of completeness, we will have a look at some other Spatial Operators.

Please keep in mind, that the filtering is done server-side when using XML Filter Expressions!

Within

In contrast to BBOX, Within only filters the features, which are completely within the bounding box.

<fes:Filter
	xmlns:fes="http://www.opengis.net/fes/2.0"
	xmlns:gml="http://www.opengis.net/gml/3.2">
  <fes:Within>
        <gml:Envelope srsName="urn:ogc:def:crs:EPSG::25832">
          <gml:lowerCorner>367441.62 5620100.532</gml:lowerCorner>
          <gml:upperCorner>367619.15 5620254.767</gml:upperCorner>
       </gml:Envelope>
   </fes:Within>
</fes:Filter>

We use a bounding box which fits the large green polygon, but as you can see an additional polygon is returned, see top right.

DWithin

DWithin uses a radius (circle) defined by

  • a distance - please check, if the Unit of Measure (uom) fits to your needs

<fes:Filter
	xmlns:fes="http://www.opengis.net/fes/2.0"
	xmlns:gml="http://www.opengis.net/gml/3.2"
	xmlns:cp="http://inspire.ec.europa.eu/schemas/cp/4.0">
   <fes:DWithin>
      <fes:ValueReference>cp:geometry</fes:ValueReference>
      <gml:Point srsName="urn:ogc:def:crs:EPSG::25832">
        <gml:coordinates>367527.734,5620177.942</gml:coordinates>
      </gml:Point>
      <fes:Distance uom='m'>2000</fes:Distance>
   </fes:DWithin>
</fes:Filter>

The WFS returns all features within the defined search radius.

Spatial Filtering using more than a rectangle

Yes, it's possible!

I'm preparing an example. Stay tuned and come back!

Imagine, you don't know the cadastral parcel number(s) of the parcel(s) you need. For this reason you can't do the attributive query we've seen before (see ).

a center point - don't forget to secifiy the Spatial Reference System aka coordinate system in srsName, check which are supported by your WFS

1st Filter
GetCapabilities
https://www.wfs.nrw.de/geobasis/wfs_nw_alkis_vereinfacht?
https://www.wfs.nrw.de/geobasis/wfs_nw_inspire-flurstuecke_alkis?
109KB
postalcodes_nw.geojson
Some postal code polygons
80KB
spatial_filtering_01_fme2022.fmw
194KB
spatial_filtering_BBOX_Within_fme2022.fmw
Spatial Filters in FeatureReader