Flexberry / Leaflet-WFST

OGC WFS-T client layer for Leaflet.
http://flexberry.github.io/Leaflet-WFST/
MIT License
151 stars 50 forks source link

Error: Geometry field 'Shape' doesn' exist inside received feature #114

Open velle opened 1 year ago

velle commented 1 year ago

For the purpose of testing I created a very simple layer (footest) on GC2, with only two features. When trying to load this layer with leaflet-WFST, the following message is printed to console (for each feature).

I don't know enough about WFS to tell if the data returned by GC2 is in fact invalid or has data missing. It appears valid to me though, and I have had no issues importing the layer into QGIS. Can anybody tell if this seems to be an error in Leaflet-WFST?

Error message in console

Geometry field 'Shape' doesn' exist inside received feature: '<cubetown:gid xmlns:cubetown="http://companyname.admin.gc2.io/companyname/cubetown">35</cubetown:gid><cubetown:id xmlns:cubetown="http://companyname.admin.gc2.io/companyname/cubetown">45</cubetown:id><cubetown:the_geom xmlns:cubetown="http://companyname.admin.gc2.io/companyname/cubetown"><gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="urn:ogc:def:crs:EPSG::3857"><gml:pointMember><gml:Point><gml:pos>2632472.43108 10411830.80244</gml:pos></gml:Point></gml:pointMember></gml:MultiPoint></cubetown:the_geom>', so feature will be skipped and won't be converted into leaflet layer

HTML/JS used for testing:

<html>
<head>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
    <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
    <!-- <script src="https://unpkg.com/leaflet-providers@1.0.13/leaflet-providers.js"></script> -->
    <script src="https://unpkg.com/leaflet-wfst@2.0.1-beta.27/dist/leaflet-wfst.min.js"></script>
    <style> #map { height: 300px; width: 300px; background-color: #ccf; } </style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map', { center: [56, 10], zoom: 16 });

L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 19,
    attribution: '© OpenStreetMap'
}).addTo(map);

//https://services.datafordeler.dk/DAR/WFSadresser/1.0.0/WFS?username=LEIXDZQLOE&password=Lyngbakken.20b
var wfsLayer = new L.WFS({
    url: 'https://companyname.admin.gc2.io/wfs/cubetown@companyname/cubetown/3857',
    typeNS: 'cubetown',
    typeName: 'footest',
    crs: L.CRS.EPSG3857
}).addTo(map);

</script>
</body>
</html>

I inspected the data in the Chrome dev tool, and the two requests are listed below, together with the response data (pretty formatted).

WFS request 1 - DescribeFeatureType

Url: https://companyname.admin.gc2.io/wfs/cubetown@companyname/cubetown/3857?

Request payload:

<wfs:DescribeFeatureType xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0">
    <TypeName>cubetown:footest</TypeName>
</wfs:DescribeFeatureType>

Response:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:gc2="http://www.mapcentia.com/gc2" xmlns:cubetown="http://companyname.admin.gc2.io/companyname/cubetown" elementFormDefault="qualified" targetNamespace="http://companyname.admin.gc2.io/companyname/cubetown" version="1.1.0">
  <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/feature.xsd"/>
  <xsd:import namespace="http://www.mapcentia.com/gc2" schemaLocation="https://companyname.admin.gc2.io/xmlschemas/gc2.xsd"/>
  <xsd:complexType name="footestType">
    <xsd:complexContent>
      <xsd:extension base="gml:AbstractFeatureType">
        <xsd:sequence>
          <xsd:element nillable="false" name="gid" maxOccurs="1" type="xsd:int" minOccurs="0">
            <xsd:simpleType>
              <xsd:restriction base="xsd:string">
                <xsd:minLength value="0"/>
                <xsd:maxLength value="256"/>
              </xsd:restriction>
            </xsd:simpleType>
          </xsd:element>
          <xsd:element nillable="true" name="the_geom" maxOccurs="1" type="gml:MultiPointPropertyType" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="footest" type="cubetown:footestType" substitutionGroup="gml:_Feature"/>
</xsd:schema>

Wfs Request 2 - GetFeature

Url: https://companyname.admin.gc2.io/wfs/cubetown@companyname/cubetown/3857?

Request payload:

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" outputFormat="text/xml; subtype=gml/3.1.1">
    <wfs:Query typeName="cubetown:footest" srsName="EPSG:3857"/>
</wfs:GetFeature>

Response:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wfs="http://www.opengis.net/wfs" xmlns:cubetown="http://companyname.admin.gc2.io/companyname/cubetown" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="2" timeStamp="2023-08-31T18:00:46.000Z" xsi:schemaLocation="http://companyname.admin.gc2.io/companyname/cubetown https://companyname.admin.gc2.io/wfs/cubetown@companyname/cubetown/3857?service=wfs&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;typeName=footest http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
  <gml:boundedBy>
    <gml:Envelope srsName="urn:ogc:def:crs:EPSG::3857">
      <gml:lowerCorner>1110463.96214 7602459.27055</gml:lowerCorner>
      <gml:upperCorner>1110654.67555 7602513.46419</gml:upperCorner>
    </gml:Envelope>
  </gml:boundedBy>
  <gml:featureMembers>
    <cubetown:footest gml:id="footest.35">
      <cubetown:gid>35</cubetown:gid>
      <cubetown:the_geom>
        <gml:MultiPoint srsName="urn:ogc:def:crs:EPSG::3857">
          <gml:pointMember>
            <gml:Point>
              <gml:pos>1110654.67555 7602459.27055</gml:pos>
            </gml:Point>
          </gml:pointMember>
        </gml:MultiPoint>
      </cubetown:the_geom>
    </cubetown:footest>
    <cubetown:footest gml:id="footest.32">
      <cubetown:gid>32</cubetown:gid>
      <cubetown:the_geom>
        <gml:MultiPoint srsName="urn:ogc:def:crs:EPSG::3857">
          <gml:pointMember>
            <gml:Point>
              <gml:pos>1110463.96214 7602513.46419</gml:pos>
            </gml:Point>
          </gml:pointMember>
        </gml:MultiPoint>
      </cubetown:the_geom>
    </cubetown:footest>
  </gml:featureMembers>
</wfs:FeatureCollection>
<!--Array
(
)
-->

Company name removed

I have removed part of the URL, which reveals the company whose data I am working on. Otherwise the data above is unedited.

mstempell commented 1 year ago

Hello, the geometry field is called the_geom in your WFS service response (classic name for this field). Check the XML data block shown to you on the error. You can identify this part of the XML data as a geometry, because it contains a GML geometry type. Here it is "MultiPoint".

So you should configure this specific field name on your WFS layer initialisation, by adding this option : geometryField: 'the_geom'