1

I have a problem using OpenLayers WFS intersection filter with GeoServer:

Context: I want to send an intersection filter request to my WFS server to get feature geometry and attributes using this Open Layers JS code:

//creating a POST request
function GeneratePOSTRequest() {
    var featureRetriver = drawShape.getSource().getFeatures();
    //retrieving the first drawed feature
    var SelectorPoly = featureRetriver[0].getGeometry();
    var featureRequest = new WFS().writeGetFeature({
        srsName: 'EPSG:3857',
        featurePrefix : 'ArchaeoSpringMap',
        featureTypes: ['paris_polygon'],
        outputFormat: 'gml3',
        filter: intersectsFilter('paris_polygon', SelectorPoly, 'EPSG:3857')
    });
    console.log(new XMLSerializer().serializeToString(featureRequest));
    //sending the request to the wfs server
    fetch('http://localhost:8081/geoserver/ArchaeoSpringMap/ows?', {
        method: 'POST',
        body: new XMLSerializer().serializeToString(featureRequest)
    }).then(function(response) {
        return response.text();
    }).then(function(text) {
        var features = new WFS().readFeatures(text);
        SelectedGeomSource.addFeatures(features);
        if (features.length > 0) {
            CartoVectorTiles.setOpacity(0.5);
        }
        else {
            window.alert("No data found");
        };
    });
};

This code send the following xml to geoserver

<GetFeature xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" outputFormat="gml3" 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"><Query typeName="ArchaeoSpringMap:paris_polygon" srsName="EPSG:3857"><Filter xmlns="http://www.opengis.net/ogc"><Intersects><PropertyName>paris_polygon</PropertyName><Point xmlns="http://www.opengis.net/gml" srsName="EPSG:3857"><pos srsDimension="2">11561769.770974282 1511007.0255549715</pos></Point></Intersects></Filter></Query></GetFeature>

Problem: after sending the request, GeoServer returns the following error:

<?xml version="1.0" encoding="UTF-8"?><ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows http://localhost:8081/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="InvalidParameterValue">
<ows:ExceptionText>Illegal property name: paris_polygon for feature type ArchaeoSpringMap:paris_polygon</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>

It's strange because if I use GGIS Server this work perfectly fine like this following exemple:

//creating a POST request
function GeneratePOSTRequest() {
    var featureRetriver = drawShape.getSource().getFeatures();
    //retrieving the first drawed feature
    var SelectorPoly = featureRetriver[0].getGeometry();
    var featureRequest = new WFS().writeGetFeature({
        srsName: 'EPSG:3857',
        featurePrefix : 'qgs',
        featureTypes: ['paris_polygon'],
        outputFormat: 'gml3',
        filter: intersectsFilter('paris_polygon', SelectorPoly, 'EPSG:3857')
    });
    console.log(new XMLSerializer().serializeToString(featureRequest));
    //sending the request to the wfs server
    fetch('http://192.168.1.12/cgi-bin/qgis_mapserv.fcgi.exe?', {
        method: 'POST',
        body: new XMLSerializer().serializeToString(featureRequest)
    }).then(function(response) {
        return response.text();
    }).then(function(text) {
        var features = new WFS().readFeatures(text);
        SelectedGeomSource.addFeatures(features);
        if (features.length > 0) {
            CartoVectorTiles.setOpacity(0.5);
        }
        else {
            window.alert("No data found");
        };
        drawSource.clear();
        WFSbutton.disabled = false;
    });
};

xml request to QGIS SERVER

<GetFeature xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" outputFormat="gml3" 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"><Query typeName="qgs:paris_polygon" srsName="EPSG:3857"><Filter xmlns="http://www.opengis.net/ogc"><Intersects><PropertyName>paris_polygon</PropertyName><Point xmlns="http://www.opengis.net/gml" srsName="EPSG:3857"><pos srsDimension="2">11561766.103877338 1511010.6978667264</pos></Point></Intersects></Filter></Query></GetFeature>

xml response from QGIS SERVER

<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml http://192.168.1.12/cgi-bin/qgis_mapserv.fcgi.exe?SERVICE=WFS&amp;VERSION=1.1.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=paris_polygon&amp;OUTPUTFORMAT=text/xml; subtype%3Dgml/3.1.1">
<gml:boundedBy>
 <gml:Envelope srsName="EPSG:3857">
  <gml:lowerCorner>11531511.71662265 1486625.30301293</gml:lowerCorner>
  <gml:upperCorner>11608993.70926311 1553476.66607341</gml:upperCorner>
 </gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
 <qgs:paris_polygon gml:id="paris_polygon.23545">
  <gml:boundedBy>
   <gml:Envelope srsName="EPSG:3857">
    <gml:lowerCorner>11561750.03055081 1510994.87817679</gml:lowerCorner>
    <gml:upperCorner>11561789.24145074 1511028.27824932</gml:upperCorner>
   </gml:Envelope>
  </gml:boundedBy>
  <qgs:geometry>
   <MultiPolygon xmlns="http://www.opengis.net/gml" srsName="EPSG:3857">
    <polygonMember xmlns="http://www.opengis.net/gml">
     <Polygon xmlns="http://www.opengis.net/gml">
      <exterior xmlns="http://www.opengis.net/gml">
       <LinearRing xmlns="http://www.opengis.net/gml">
        <posList xmlns="http://www.opengis.net/gml" srsDimension="2">11561752.26563166 1511025.80552321 11561783.54057308 1511028.27824932 11561785.85424495 1511028.01523221 11561787.08286404 1511027.06268114 11561787.49721357 1511025.69567028 11561789.24145074 1511001.33655126 11561788.84719018 1510998.32302875 11561786.81125346 1510997.3553245 11561757.16799412 1510995.02709061 11561754.58413823 1510994.87817679 11561753.21949949 1510995.83005925 11561752.53185016 1510997.46961013 11561751.8146061 1511005.54303815 11561751.12692349 1511007.18258939 11561750.03055081 1511008.95709617 11561750.1565403 1511011.14799583 11561750.82469164 1511013.75209002 11561750.10244709 1511022.92068964 11561750.23029073 1511024.70089436 11561750.77059861 1511025.52478495 11561752.26563166 1511025.80552321</posList>
       </LinearRing>
      </exterior>
     </Polygon>
    </polygonMember>
   </MultiPolygon>
  </qgs:geometry>
  <qgs:type>5</qgs:type>
 </qgs:paris_polygon>
</gml:featureMember>
</wfs:FeatureCollection>

It's look like the problem came from GeoServer but I haven't been able to resolve it. How can I fix this problem?

4
  • 2
    The "paris_polygon" seems to be the name of the feature type but the propertyname in the filter should be the name of the geometry property. For me it seems that QGIS server is accepting an invalid request because the name of the geometry is "qgs:geometry".
    – user30184
    Commented Nov 1, 2021 at 20:58
  • 1
    The line filter: intersectsFilter('paris_polygon', SelectorPoly, 'EPSG:3857') should be filter: intersectsFilter('geometry', SelectorPoly, 'EPSG:3857')
    – Ian Turton
    Commented Nov 2, 2021 at 8:35
  • 1
    Thank you, i changed filter: intersectsFilter('paris_polygon', SelectorPoly, 'EPSG:3857') to filter: intersectsFilter('geom', SelectorPoly, 'EPSG:3857') and it works. My geometry field is called geom, probably because i use PostGIS behing GeoServer.
    – vprint
    Commented Nov 2, 2021 at 9:34
  • 1
    The name of the geometry field is not fixed in databases. Some defaults used by different importers are "geometry", "wkb_geometry", "the_geom", and "geom". Fortunately WFS user can easily check the real name with DescribeFeatureType.
    – user30184
    Commented Nov 2, 2021 at 10:50

1 Answer 1

1

Following user30184 and Ian Turton answer, i changed this line filter: intersectsFilter('paris_polygon', SelectorPoly, 'EPSG:3857') by filter: intersectsFilter('geom', SelectorPoly, 'EPSG:3857') and now it's work fine.

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.