Skip to content

Enhance datatype determination and improve service_ok util #994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 17, 2025

Conversation

KaiVolland
Copy link
Contributor

This PR contains two enhancements.

  1. The datatype determination for featuretype attributes is updated to support all possible variants of the GML spec. Currently only the simplest case (<xsd:element minOccurs="0" maxOccurs="1" name="objectid" type="xsd:int"/>) is supported.

  2. The service_ok util now uses requests.get with stream=True. This adds support for a known bug in ArcGIS servers where the response header of the HEAD request response with the wrong content-type. stream=True should ensure, that there is no data fetched with the request. The traffic should be almost the same as with the HEAD request.

@KaiVolland
Copy link
Contributor Author

Hi @geographika. Maybe you can have a look at this. 👋

@geographika
Copy link
Contributor

Thanks (and hi!) @KaiVolland - a very nice addition. I've been testing the branch using pip install git+https://github.com/KaiVolland/OWSLib.git@arcgis-server-support and the code below:

import json
from owslib.wfs import WebFeatureService

WFS_SERVICE_URL = 'https://geoportal.stadt-koeln.de/arcgis/services/basiskarten/adressen_stadtteil/MapServer/WFSServer?SERVICE=WFS&request=GetCapabilities'

wfs = WebFeatureService(WFS_SERVICE_URL, version="2.0.0")
schema = wfs.get_schema('adressen_stadtteil:Blumenberg')
print(json.dumps(schema, indent=4))

Output:

{
    "properties": {
        "objectid": "int",
        "Nummer": "string",
        "Adresse": "string",
        "Strassenschl\u00fcssel": "string",
        "Stra\u00dfe": "string",
        "Amtl._Stra\u00dfenname": "string",
        "Stra\u00dfe__Stadtbezirk_": "string",
        "Hausnummer": "string",
        "Geb\u00e4ude_ID_ALKIS": "string",
        "Nutzung__ALKIS_Geb\u00e4udefunktion_": "string",
        "Blockseite": "string",
        "Stadtviertel__Nr._": "string",
        "Stadtviertel": "string",
        "Statistisches_Quartier__Nr._": "string",
        "Statistisches_Quartier": "string",
        "Stadtteil__Nr._": "string",
        "Stadtteil": "string",
        "Stadtbezirk__Nr._": "string",
        "Stadtbezirk": "string",
        "Stimmbezirk": "string",
        "Postleitzahlgebiet": "string",
        "Schiedsamtsbezirk": "string",
        "Sozialraum__Nr._": "string",
        "Sozialraum": "string",
        "globalid": "string"
    },
    "required": [
        "objectid",
        "globalid"
    ],
    "geometry": "Point",
    "geometry_column": "shape"
}

If I try and run the code without your PR I'm getting errors, so I guess this also fixes errors with missing types?

>>> schema = wfs.get_schema('adressen_stadtteil:Blumenberg')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\VirtualEnvs\misc\lib\site-packages\owslib\feature\__init__.py", line 391, in get_schema
    return get_schema(self.url, typename, self.version, auth=self.auth)
  File "C:\VirtualEnvs\misc\lib\site-packages\owslib\feature\schema.py", line 62, in get_schema
    return _construct_schema(elements, nsmap)
  File "C:\VirtualEnvs\misc\lib\site-packages\owslib\feature\schema.py", line 126, in _construct_schema
    data_type = element.attrib["type"].replace(gml_key + ":", "")
  File "src\\lxml\\etree.pyx", line 2548, in lxml.etree._Attrib.__getitem__

For mocking server results an option is to use pytest_httpserver added in #978 with an example at https://github.com/geopython/OWSLib/pull/978/files#diff-6830fccba0ba34d726c392cad7487e14412cb980a123aa263f93370b95b69ba3

I'm also fine with the monkeypatch approach.
Noted re stream=True - makes sense to go to a GET request without worrying about HEAD.

It would be nice to get another sample test with a few other datatypes if you have one - most of the current example are xsd:string.

I'm +1 on merging, but will leave open for a few days to see if anyone else has feedback.

@KaiVolland
Copy link
Contributor Author

Thanks for the feedback. I parametrized the data_type tests to cover more cases.

I kept the new test (tests/test_wfs_schema_arcgis_server.py) similiar to the existing one so i used the monkey test. 🙂

@geographika
Copy link
Contributor

Merging - thanks @KaiVolland.

@geographika geographika merged commit 1d011de into geopython:master May 17, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants