1

Created the WFS feature request as following:

this.map.getViewport().addEventListener("click", (evt) => { 

  //Point transformation to EPSG:25830
  var proyeccion = getProjection('EPSG:25830');
  var p = new Point(this.map.getEventCoordinate(evt)).transform(this.map.getView().getProjection(),proyeccion);

  //WFS Feature Request
  var featureRequest = new WFS().writeGetFeature({
    srsName: 'EPSG:25830',
    featurePrefix: 'CP',
    featureTypes: ['CadastralParcel'],
    outputFormat: 'application/json',
    filter: containsFilter('MultiPolygon',p,'EPSG:25830')
  });

  fetch('https://inspire.navarra.es/services/CP/wfs', {
    method: 'POST',
    body: new XMLSerializer().serializeToString(featureRequest)
  }).then((response) => {
    return response.json();
  }).then((json) => {
    var features = new GeoJSON().readFeatures(json);
    this.vectorSource.addFeatures(features);
  });
});

This makes the getFeature request correctly using POST, with the following request payload:

<GetFeature xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" outputFormat="application/json" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
    <Query typeName="CP:CadastralParcel" srsName="EPSG:25830">
        <Filter xmlns="http://www.opengis.net/ogc">
            <Contains>
                <PropertyName>MultiPolygon</PropertyName>
                <Point xmlns="http://www.opengis.net/gml" srsName="EPSG:25830">
                    <pos srsDimension="2">586784.8369967575 4722127.891344394</pos>
                </Point>
            </Contains>
        </Filter>
    </Query>
</GetFeature>

But the request above returns an empty FeatureCollection when clicking a point where there is a feature. The type of Features that I was supposed to get were Polygon.

{"type":"FeatureCollection","totalFeatures":"unknown","features":[],"crs":null}

Guess it could be because of the projections, but don't know where the mistake is.

Request details

EDIT

I'm using projection EPSG:25830. Defined like this:

proj4.defs("EPSG:25830","+proj=utm +zone=30 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
register(proj4);

Added to the map's view and layers as following:

const proyeccion = getProjection('EPSG:25830');

view: new View({
    projection: proyeccion,
    center: fromLonLat([-1.629950,42.63],proyeccion),
    zoom: 9
})

//WMS
source: new TileWMS({
    url: 'http://localhost:3000/idena',
    params: {'LAYERS': 'catastro'},
    projection: proyeccion
})
  • If spatial reference issues are the likely cause, then it's probably pretty important to specify what the spatial references in use are. Please Edit the question. – Vince Sep 3 at 10:33
  • Projection is not a parameter of the Point geometry constructor. If your view projection is different to the data projection replace var p = new Point(this.map.getEventCoordinate(evt),proyeccion); with var p = new Point(this.map.getEventCoordinate(evt)).transform(map.getView().getProjection(),proyeccion); otherwise simply remove proyeccion. Also there is unlikely to be a point feature at the exact coordinate of the click event as that can only be calculated to the accuracy of one pixel, you should filter for features within a one pixel (at least) tolerance of that. – Mike Sep 3 at 10:47
  • 1
    <PropertyName>Point</PropertyName> refers to the name of the geometry field of your featuretype CP:CadastralParcel. I guess that it is not correct. – user30184 Sep 3 at 10:56
  • 1
    Check the schema with DescribeFeatureType. Example: demo.geo-solutions.it/geoserver/…. In this case the name of the geometry is the_geom. For you it seems to be CP:geometry. – user30184 Sep 3 at 11:02
  • 1
    Right, you should continue and check the CadastralParcels.xsd. An easier way is to read one feature inspire.navarra.es/services/CP/…. – user30184 Sep 3 at 11:10
2

You have used wrong PropertyName in your filter

<Filter xmlns="http://www.opengis.net/ogc">
    <Contains>
        <PropertyName>MultiPolygon</PropertyName>
        <Point xmlns="http://www.opengis.net/gml" srsName="EPSG:25830">
            <pos srsDimension="2">586784.8369967575 4722127.891344394</pos>
        </Point>
    </Contains>
</Filter>

The PropertyName must be the name of the geometry as it is announced in the schema of the PropertyType. In WFS the schema can be read with the DescribeFeatureType request. For example the schema of a GeoServer demo layer https://demo.geo-solutions.it/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typename=states

shows that the name of the geometry is "the_geom"

<xsd:element name="the_geom" type="gml:MultiSurfacePropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>

In your case the request is https://inspire.navarra.es/services/CP/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typename=CP:CadastralParcel

The response does not show the schema directly but it has a reference to the INSPIRE schema document http://inspire.ec.europa.eu/schemas/cp/4.0/CadastralParcels.xsd that you can try to interpret. Another option is to read one feature with GetFeature request and check the name of the geometry from the response https://inspire.navarra.es/services/CP/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=CP:CadastralParcel&maxFeatures=1

<gml:featureMember>
<CP:CadastralParcel gml:id="ES.RRTN.CP.1010001">
<CP:areaValue uom="m2">101.2779</CP:areaValue>
<CP:beginLifespanVersion nilReason="other:unpopulated" xsi:nil="true"/>
<CP:geometry>MULTIPOLYGON (((42.64858704034896 -2.141289282470453, ... 

The full name of the geometry is CP:geometry but your experience seems to suggest that the namespace part must be dropped and filter that works looks like

<Filter xmlns="http://www.opengis.net/ogc">
    <Contains>
        <PropertyName>geometry</PropertyName>
        <Point xmlns="http://www.opengis.net/gml" srsName="EPSG:25830">
            <pos srsDimension="2">586784.8369967575 4722127.891344394</pos>
        </Point>
    </Contains>
</Filter>

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.