3

How do I generate geometric OGC filters for use in a WFS GetFeature request such as:

<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:Intersects>
        <ogc:PropertyName>geom</ogc:PropertyName>
        <gml:Box xmlns:gml="http://www.opengis.net/gml">
            <gml:coordinates decimal="." cs="," ts=" ">1298543.0367787,7107400.531374 1299312.4070614,7203464.9016567</gml:coordinates>
        </gml:Box>
    </ogc:Intersects>
</ogc:Filter>

The OpenLayers 2 supported geometric filters (e.g., Intersections). How do I write a filter in the OL3?
ol.format.ogc.filter seems does not support (geometric filters).

1

As the library has changed over the time, you can now provide filters for spatial operations using ol.format.filter.* functions (previously in the namespace ol.format.ogc.filter.*)

Using something like below will work:

  var featureRequest = new ol.format.WFS().writeGetFeature({
  srsName: 'EPSG:3857',
  featureNS: 'http://openstreemap.org',
  featurePrefix: 'osm',
  featureTypes: ['water_areas'],
  outputFormat: 'gml3',
  filter: ol.format.filter.and(
    ol.format.filter.intersects('the_geom', polygon, 'EPSG:4326'),
    ol.format.filter.equalTo('waterway', 'riverbank')
  )
});

where polygon is an ol.geom.Geometry.

Be aware that I had to invert X and Y coordinates in my polygon to make things working correctly.

You can see an example in action to illustrate (PS: working in Chrome, not in FF, didn't debug more because do not own the remote server...).

  • Yes, it is I myself added to the library - not previously... In any case, thank you – t1nk Jan 27 '17 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.