I'm working on a QGIS plugin that adds WFS vectors from this URI: https://wxs.ign.fr/agriculture/geoportail/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetCapabilities
I'm using the code below :
def import_wfs(self,layer_name):
wfs_url = "https://wxs.ign.fr/agriculture/geoportail/wfs?VERSION%3D2.0.0"
params = {
'pagingEnabled': 'true',
'preferCoordinatesForWfsT11': 'false',
'restrictToRequestBBOX': '1',
'srsname': 'EPSG:4326',
'typeName': 'RPG.2011:rpg_2011',
'url': wfs_url,
'version': 'auto'
}
wfs_layer = QgsVectorLayer('{}?{}'.format(wfs_url, '&'.join(['{}={}'.format(k, v) for k, v in params.items()])), layer_name, 'WFS')
QgsProject.instance().addMapLayer(wfs_layer)
The code seem to work and display the vectors, however I get a "loading" msg box that usually ends up freezing QGIS.
The meta data of the layer is this :
However, when I add the vectors manually through "Add Layer" > "Add WFS Layer" and add 'https://wxs.ign.fr/agriculture/geoportail/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetCapabilities', it works just fine, however the metadata is slightly different (doesn't have the URI in the start of the source), see the picture below :
The layer in green represents the layer added through PyGIS and is super buggy, the one in pink is the one i added manually through the wfs adress 'https://wxs.ign.fr/agriculture/geoportail/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetCapabilities'
What is wrong here?
https://wxs.ign.fr/agriculture/geoportail/wfs?
without the version. The GetCapabilities response has a error in it though reporting the URL ashttps://wxs.ign.fr/agriculture/geoportail/wfs/
and that can cause an issue unless you tell QGIS to ignore the URLS in the GetCapabilities response.'version': 'auto'
is not correct. Your GetFeature requests will need a version number (`version=auto as per your metadata is not correct, neither is version =2.0.0 version=auto).Key=Value&
format so you should be adding the & at the end not at the beginning .https://wxs.ign.fr/agriculture/geoportail/wfs?version=2.0.0?
is incorrect, so isversion=2.0.0&version=auto&
in your first image. Servers are at liberty to choose which of the repeated parameter values to use so having two version values, one of which is incorrect may cause an issue