geocompx / geocompy

Geocomputation with Python: an open source book
https://py.geocompx.org/
Other
298 stars 54 forks source link

Add example for fetching data from WFS? #227

Closed anitagraser closed 4 weeks ago

anitagraser commented 5 months ago

Chapter 7 "Geographic data I/O" would profit from an example for fetching vector data from OGC WFS services.

Here's how I did it in a toy project:

https://github.com/anitagraser/ogd-at-lab/blob/1fd7c034b57d23fb95a93d40babbf0ae05021f4e/notebooks/utils/dataaccess.py#L6-L19


def get_gdf_from_wfs(layer):
    """
    Get geopandas.GeoDataFrame from data.wien.gv.at WFS service based on layer name

    Parameters
    ----------
    layer : string
        WFS layer name 
    """
    file = f'data/{layer}.json'
    url = f"https://data.wien.gv.at/daten/geo?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:{layer}&srsName=EPSG:4326&outputFormat=json"
    if not exists(file):
        urlretrieve(url, file)
    return gpd.read_file(file)