Skip to content

Instantly share code, notes, and snippets.

@psd
Created June 4, 2018 09:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psd/b6ed4a09e48fb79bb4e92823651ea2ec to your computer and use it in GitHub Desktop.
Save psd/b6ed4a09e48fb79bb4e92823651ea2ec to your computer and use it in GitHub Desktop.
Grab GML from a WFS server
#!/usr/bin/env python3
"""
https://geopython.github.io/OWSLib/
"""
from owslib.wfs import WebFeatureService
url='http://inspire.misoportal.com/geoserver/mid_sussex_district_council_msdc_3830_tpo_point/wfs?service=wfs&version=2.0.0&request=GetCapabilities'
url='http://environment.data.gov.uk/ds/wfs?INTERFACE=ENVIRONMENTWFS--7a955570-d465-11e4-a37c-f0def148f590'
url='https://maps.runnymede.gov.uk/geoserver/wfs?service=WFS&request=GetFeature&typeName=planning:tree_preservation_orders&outputFormat=shape-zip'
url='http://services.maidstone.gov.uk/maps/astun.ishare.web/getows.ashx?mapsource=Maidstone/Swale_Inspire&TypeName=tree_preservation_orders&version=1.1.0&request=GetFeature&service=WFS'
url='http://inspirewfs.stalbans.gov.uk/INSPIRE/WEBSERVICE/wfs.exe?service=wfs&request=GetCapabilities'
url='http://inspire.misoportal.com/geoserver/norwich_city_council_tpo_trees_trees/wms?request=getCapabilities'
try:
wfs = WebFeatureService(url=url, version='2.0.0')
except:
wfs = WebFeatureService(url=url, version='1.1')
print(url, wfs.contents)
for layer in list(wfs.contents):
feature = wfs.getfeature(typename=layer)
path = 'out/%s.gml' % layer
print(path)
try:
out = open(path, 'wb')
out.write(bytes(feature.read(), 'UTF-8'))
out.close()
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment