2

I am using OpenLayers to create a web app which allows users to define a polygon as an area of interest, and then query the features which fall within the bounding box and return the data to present it in a few other forms, like a pie chart for example. Right now, I am using the bbox parameter in my WFS GetFeature request. However, the features being returned by the request are almost completely wrong. Here is a link to a prototype of the app to see what I mean. If you open the statistics panel on the side bar, it gives you instructions to generate results which appear on the same panel.

From what I've read, the CQL Intersects filter may be a better solution to query features, but my attempts have not been successful. I have tried quite a few ways to use the CQL filter but have not gotten it to work quite right just yet.

const params = {
      service: "WFS",
      version: "2.0.0",
      request: "GetFeature",
      typename: "timeseries:U2006_CLC2000_V2020_20u1_3857,timeseries:U2012_CLC2006_V2020_20u1U2012_CLC2006_V2020_20u1," +
      "timeseries:U2018_CLC2012_V2020_20u1U2018_CLC2012_V2020_20u1,timeseries:U2018_CLC2018_V2020_20u1U2018_CLC2018_V2020_20u1",
      srsName: "EPSG:3857",
      outputFormat: "text/xml; subtype=gml/3.2",
      cql_filter: "Intersects(geom,POLYGON((" + minx + " " + miny + "," + maxx + " " + maxy + "))",
      // bbox: extent.join(',') + ",EPSG:3857"
  };

  $.ajax('https://thawing-waters-16552.herokuapp.com/https://clc-timeseries.gaf.de/wfs?', {
      type: "GET",
      data: params,
      dataType: "xml",
      contentType: "text/xml; subtype=gml/3.2"
  }).then(data => {doing stuff with data here})

I am getting a 400 Bad Request Error when requesting it as it is above.

1
1

The filter should be an XML string. Where polygon is a single ring OpenLayers polygon geometry, e.g. you have drawn a polygon as in https://jsfiddle.net/0bjk6u7L/ you should be able to set it up similar to this:

const coords = polygon.getCoordinates()[0].join(' ');

const xml = '<ogc:Filter>' +
      '<ogc:Intersects>' +
      '<ogc:PropertyName>SHAPE</ogc:PropertyName>' +
      '<gml:Polygon srsName="EPSG::3857">' +
      '<gml:outerBoundaryIs>' +
      '<gml:LinearRing>' +
      '<gml:coordinates>' + coords + '</gml:coordinates>' +
      '</gml:LinearRing>' +
      '</gml:outerBoundaryIs>' +
      '</gml:Polygon>' +
      '</ogc:Intersects>' +
      '</ogc:Filter>';


const params = {
      service: "WFS",
      version: "2.0.0",
      request: "GetFeature",
      typename: "timeseries:U2006_CLC2000_V2020_20u1_3857,timeseries:U2012_CLC2006_V2020_20u1U2012_CLC2006_V2020_20u1," +
      "timeseries:U2018_CLC2012_V2020_20u1U2018_CLC2012_V2020_20u1,timeseries:U2018_CLC2018_V2020_20u1U2018_CLC2018_V2020_20u1",
      srsName: "EPSG:3857",
      outputFormat: "text/xml; subtype=gml/3.2",
      filter: xml,
  };
5

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.