0

I have a WFS running on URL that is mentioned in the code below. i want to get all the features available in the service as a shapefile so i can open it and visualize it in QGIS or any other GIS software. The servies provides the ability to download the shapefile as can be viewed here :

https://www.geoseaportal.de/wss/service/Site_Development_Plan_2020/guest?SERVICE=WFS&REQUEST=GetCapabilities&VERSION=2.0.0

I have tried the below code to fetch the data and save as a shapefile but it just creates an empty point shapefile which is not correct. How can i download it correctly?

from owslib.wfs import WebFeatureService

eaWFS = WebFeatureService(url='https://www.geoseaportal.de/wss/service/Site_Development_Plan_2020/guest?SERVICE=WFS', version='2.0.0')

floodData = eaWFS.getfeature(typename='Site_Development_Plan_2020:All', bbox=(419000,419000,421000,421000), outputFormat='SHAPE-ZIP')

out = open('C:\\Users\Chaudhr1\\arcgis\DATA.zip', 'wb')
out.write(floodData.read())
out.close()
6
  • Does the url work in your browser?
    – Ian Turton
    Mar 30 at 19:22
  • 1
    I am going to assume that you are using the same code from here and you didn't change your bbox values?
    – Binx
    Mar 30 at 19:30
  • 1
    This WFS opens easily in QGIS, and Export >> Save Features As... works. Why are you using code?
    – Pointdump
    Mar 30 at 19:30
  • @IanTurton yes it does
    – Rehan
    Mar 30 at 20:03
  • @Binks yes i did not. but i constructed url manually for get feataures and was able to download the zip shapefile but i dont know how to do the same with pytthon
    – Rehan
    Mar 30 at 20:05

1 Answer 1

4

As @Binks alludes to in their comment, your bounding box is incorrect for the data you are querying. This runs in the Python console of QGIS, but you can copy-paste the printed bbox tuple into your Jupyter Notebook.

from owslib.wfs import WebFeatureService

# add WFS to QGIS and get the extent
ext = iface.activeLayer().extent()  

# construct a bbox tuple from the extent
bbox = (ext.xMinimum(), ext.yMinimum(), ext.xMaximum(), ext.yMaximum())

print(bbox)
# (3905180.8005, 3416324.4063, 4611648.3389, 3649276.3886)

eaWFS = WebFeatureService(url='https://www.geoseaportal.de/wss/service/Site_Development_Plan_2020/guest?SERVICE=WFS', version='2.0.0')

floodData = eaWFS.getfeature(typename='Site_Development_Plan_2020:All', bbox=bbox, outputFormat='SHAPE-ZIP')

out = open(r'C:\\Users\Chaudhr1\\arcgis\DATA.zip', 'wb')
out.write(floodData.read())
out.close()

enter image description here

1
  • alright. so thats the issue. i just have one additional question. so when i try to sepcify "srsname" in "getfeature" like srsname='urn:ogc:def:crs:EPSG::3035', it give me error `unexpected keyword argument. could you please update your code on how to specify the crs as well while fetching the features?
    – Rehan
    Mar 31 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.