24 lines
693 B
Python
24 lines
693 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
from owslib.wfs import WebFeatureService
|
|
|
|
def get_wfs(url, layer, bbox=None):
|
|
from geopandas import read_file
|
|
from requests import Request
|
|
wfs = WebFeatureService(url=url)
|
|
item = dict(wfs.items())[layer]
|
|
crs = item.crsOptions[0].getcode()
|
|
params = dict(service='WFS', version=wfs.version, request='GetFeature',
|
|
typeName=layer)
|
|
q = Request('GET', url, params=params).prepare().url
|
|
data = read_file(q, bbox=bbox)
|
|
data.set_crs(crs=crs, inplace=True)
|
|
if crs != 'EPSG:2154':
|
|
data.to_crs(epsg=2154, inplace=True)
|
|
return data
|
|
|
|
def list_layer(url):
|
|
wfs = WebFeatureService(url=url)
|
|
lst = list(wfs.contents)
|
|
return lst |