TransWikia.com

Connecting to several WFS using python/OWSLIB/OGR2OGR

Geographic Information Systems Asked on July 8, 2021

I’m trying to download a lot of datasets from different WFS URLs using ogr2ogr (and to an extent, owslib) in Python. My problem arises when I try to connect to a second WFS.

In my test code, I have first tried connecting to one WFS, then downloading the layer. This went fine. Afterwards, I replaced the URL with a second WFS URL. this time I got the error:

ConnectionError: ('Connection aborted.', ConnectionResetError(10054 An existing connection was forcibly closed by the remote host)). 

In the first part of the code I try to extract the version number from the WFS:

import subprocess
from owslib.wfs import WebFeatureService as wfsmod

#connecting to second WFS using owslib
url = 'http://wfs2-miljoegis.mim.dk/raastofpaahavet/ows? 
version=1.1.0&OUTPUTFORMAT=GML2'
wfs = wfsmod(url)
version =  (wfs.identification.version)
typenam ="rashavtilladelser20auktion"

The connection error happens at line “wfs = wfsmod(url)”.

I also try to download a specific layer from this url using ogr2ogr/subprocesses:

if str(version) == "2.0.0":
    #layername is the specific title of the layer on the WFS server.
    layername = "&TYPENAMES="+layername
else:
    layername = "&TYPENAME="+layername

cmd =  [r"C:OSGeo4Wbinogr2ogr.exe", 
    "-f",
    "ESRI Shapefile", 
    r"C:havplanhavplan_datawfs_downloadshavbrugszoner.shp", 
     "WFS:"+url+"version="+str(version)
     +"&request=GetFeature"+layername]
subprocess.check_call(cmd)

as far as I understand, the error happens because I can only connect to one WFS at a time in Python. Is there some way to close the connection to a WFS in owslib and ogr2ogr using a command?

One Answer

Late answer, but have you tried simply deleting the WFS object ?

del wfsmod

Answered by Darth Kangooroo on July 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP