1

I need to get all attribute names and all their restrictions of the WFS feature type. The get_schema method of the owslib.wfs WebFeatureService is not working and throwing an error.

Code:

from owslib.wfs import WebFeatureService
wfs = WebFeatureService(url='https://maps.helcom.fi/arcgis/services/MADS/Human_Activities/MapServer/WFSServer', version='2.0.0')
schema = wfs.get_schema('Human_Activities:Dredging_sites_points_36_2')

Error message:

Traceback (most recent call last):
  File "C:\...\test.py", line 14, in <module>
    schema = wfs.get_schema('Human_Activities:Dredging_sites_points_36_2')
  File "C:\...\Lib\site-packages\owslib\feature\__init__.py", line 380, in get_schema
    return get_schema(self.url, typename, self.version, auth=self.auth)
  File "C:\...\Lib\site-packages\owslib\feature\schema.py", line 62, in get_schema
    return _construct_schema(elements, nsmap)
  File "C:\...\Lib\site-packages\owslib\feature\schema.py", line 122, in _construct_schema
    data_type = element.attrib["type"].replace(gml_key + ":", "")
  File "src/lxml/etree.pyx", line 2496, in lxml.etree._Attrib.__getitem__
KeyError: 'type'

The corresponding call for DescribeFeatureType request works fine: https://maps.helcom.fi/arcgis/services/MADS/Human_Activities/MapServer/WFSServer?request=DescribeFeatureType&service=WFS&version=2.0.0&typeNames=Human_Activities:Dredging_sites_points_36_2

What is a problem?

Is there any other way to get WFS feature type schema in Python than using owslib.wfs WebFeatureService get_schema?

2
  • Try to capture the http request that owslib generates.
    – user30184
    Commented Mar 12 at 13:54
  • I don't know how to do that.. Commented Mar 13 at 5:34

1 Answer 1

2

Ogrinfo can read the schema despite giving some error. The error comes because GDAL sends first DescribeFeatureType with a TypeNames argument that is listing all the 156 feature types and obviously the command string gets so long that the server denies it. I can't say if owslib tries to do something similar.

ogrinfo WFS:"https://maps.helcom.fi/arcgis/services/MADS/Human_Activities/MapServer/WFSServer" Human_Activities:Dredging_sites_points_36_2 -so
INFO: Open of `WFS:https://maps.helcom.fi/arcgis/services/MADS/Human_Activities/MapServer/WFSServer'
      using driver `WFS' successful.
Metadata:
  TITLE=WFS
ERROR 1: HTTP error code : 404
ERROR 1: Error returned by server : HTTP error code : 404 (0)

Layer name: Human_Activities:Dredging_sites_points_36_2
Metadata:
  TITLE=Dredging_sites_points_36_2
Geometry: Point
Feature Count: 0
Extent: (1060002.744600, 7173177.611800) - (2820680.049400, 9285403.858400)
Layer SRS WKT:
PROJCRS["WGS 84 / Pseudo-Mercator",
    BASEGEOGCRS["WGS 84",
        ENSEMBLE["World Geodetic System 1984 ensemble",
            MEMBER["World Geodetic System 1984 (Transit)"],
            MEMBER["World Geodetic System 1984 (G730)"],
            MEMBER["World Geodetic System 1984 (G873)"],
            MEMBER["World Geodetic System 1984 (G1150)"],
            MEMBER["World Geodetic System 1984 (G1674)"],
            MEMBER["World Geodetic System 1984 (G1762)"],
            MEMBER["World Geodetic System 1984 (G2139)"],
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]],
            ENSEMBLEACCURACY[2.0]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4326]],
    CONVERSION["Popular Visualisation Pseudo-Mercator",
        METHOD["Popular Visualisation Pseudo Mercator",
            ID["EPSG",1024]],
        PARAMETER["Latitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["False easting",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["easting (X)",east,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["northing (Y)",north,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Web mapping and visualisation."],
        AREA["World between 85.06┬░S and 85.06┬░N."],
        BBOX[-85.06,-180,85.06,180]],
    ID["EPSG",3857]]
Data axis to CRS axis mapping: 1,2
Geometry Column = Shape
gml_id: String (0.0) NOT NULL
OBJECTID: Integer (0.0)
Dredging_ID: String (50.0)
Deposit_site__Helcom_site_ID_: String (50.0)
Deposit_site_link: String (200.0)
Unique_ID: String (100.0)
Site_name: String (250.0)
Type_of_area_dredged: String (50.0)
Dredging_activity: String (50.0)
Material_dredged: String (100.0)
Year: Real (0.0)
Country: String (50.0)
Sub-basin: String (50.0)
Quality_flag: String (50.0)
dep_geometry: String (50.0)

With Python it is possible to use gdal.VectorInfo instead of the ogrinfo binary https://gdal.org/api/python/osgeo.gdal.html#osgeo.gdal.VectorInfo.

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.