Tuesday 20 March 2018

Loading a WFS layer using pyqgis


I'm trying to load a WFS layer in PyQGIS. My WFS uri is for county boundaries here in England. It's open data and pretty light, if you were wanting to recreate the issue.


Here's my code:


uri = 'http://www.geostore.com/OGC/OGCInterface?SERVICE=WFS&UID=UDATAGOV2011&PASSWORD=datagov2011&INTERFACE=ENVIRONMENTWFS&VERSION=2.0.0&LC=0'
layer = QgsVectorLayer(uri, "WFS_Layer", "WFS")
if not layer.isValid():
print "Layer failed to load!"


Sure enough, the layer is not valid.


I'm following (to the best of my limited ability) the QGIS instructions here: http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html


I'm losing the thread at this part:


enter image description here


Where in the declaration of vlayer is the uri being passed in? I feel I'm missing something fundamental.


Can anyone post working code? It'd be awesome to be able to get PyQGIS and WFS working nicely!




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...