This relates to the question here: Reading data to geopandas using WFS?

Is there a way to to do the same with a service that does not supply the data in GeoJSON format, but in GML-format?

The webservice is: https://arealinformation.miljoeportal.dk/gis/services/DAIdb/MapServer/WFSServer

And I want to read a single layer.


1 Answer 1

import geopandas as gp
import requests
from fiona import BytesCollection    

def wfs2gp_df(layer_name, url, bbox=None, wfs_version="2.0.0", outputFormat='application/gml+xml; version=3.2'):
    params = dict(service='WFS', version=wfs_version,request='GetFeature', typeName=layer_name, outputFormat=outputFormat)
    with BytesCollection(requests.get(url,params=params).content) as f:
        df = gp.GeoDataFrame.from_features(f)
    return df

wfs2gp_df('your_wfs_layer_name', 'your_wfs_url').head()
  • Using outputFormat=json did the trick for me. For some reason I failed to import XML/GML into GeoPandas. Jan 14, 2022 at 11:35
  • It is not guaranteed that the WFS server offers the json format
    – sal
    Jan 15, 2022 at 17:57
  • yes, that's correct. However, the server I'm working with can do that and I got results with JSON output. Obviously it would be great if XML/GML would work in my project. Jan 16, 2022 at 10:33

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.