0

OpenLayers 2 could generate geometric filter method WFS GetFeature.

Example JS:

var filter = new OpenLayers.Filter.Spatial({ type: OpenLayers.Filter.Spatial.INTERSECTS, value: geometry, projection: "EPSG:3067" });

var parser = new OpenLayers.Format.Filter.v1_1_0();
var filterAsXml = parser.write(filter);
var xml = new OpenLayers.Format.XML();
var filterAsString = xml.write( filterAsXml );  

Example XML:

<wfs:GetFeature
  xmlns:wfs="http://www.opengis.net/wfs"
  service="WFS"
  version="1.1.0"
  outputFormat="json"
  xsi:schemaLocation="http://www.opengis.net/wfs
  http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="LiVi:LIIKENNE_ELEMENTTI" srsName="EPSG:3067" xmlns:LiVi="http://site.ru/">
    <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
      <ogc:Intersects>
        <ogc:PropertyName>GEOMETRY</ogc:PropertyName>
        <gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:3067">
          <gml:exterior>
            <gml:LinearRing>
              <gml:posList>308082.07106781186 6833724.928932188 308082.07106781186 6833739.071067812 308067.92893218814 6833739.071067812 308067.92893218814 6833724.928932188 308082.07106781186 6833724.928932188</gml:posList>
            </gml:LinearRing>
          </gml:exterior>
        </gml:Polygon>
      </ogc:Intersects>
    </ogc:Filter>
  </wfs:Query>
</wfs:GetFeature>

They have a not working example:

var f = ol.format.wfs.filter;
var request = new ol.format.WFS().writeGetFeature({
    srsName: 'urn:ogc:def:crs:EPSG::4326',
    featureNS: 'http://www.openplans.org/topp',
    featurePrefix: 'topp',
    featureTypes: ['states'],
    filter: f.and(
      f.bbox('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326'),
      f.like('name', 'New*')
    )
});  

Either he recently appeared... Judging by the projection - a blank for WFS 2.0.0.

How do I write a geometric filter in the OL3?

PS2
Sorry for my English.

1 Answer 1

1

There is a typo in the OpenLayers documentation, which will be fixed with https://github.com/openlayers/ol3/pull/5653.

To make the example work, change ol.format.wfs.filter to ol.format.ogc.filter:

var f = ol.format.ogc.filter;
var request = new ol.format.WFS().writeGetFeature({
    srsName: 'urn:ogc:def:crs:EPSG::4326',
    featureNS: 'http://www.openplans.org/topp',
    featurePrefix: 'topp',
    featureTypes: ['states'],
    filter: f.and(
      f.bbox('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326'),
      f.like('name', 'New*')
    )
});

However, the only geometry-like filter OpenLayers supports is BBOX. Other geometry filters, like the one in your WFS XML above, are not supported by OpenLayers 3. If you need full OGC filter support, you may want to have a look at https://github.com/highsource/ogc-schemas, which provides (among others) OGC filter bindings for Jsonix.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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