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')


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 : enter image description here

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 : enter image description here

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' enter image description here

What is wrong here?

  • You have fixed the version in the URL but left auto in the parameters which may cause a problem,
    – Ian Turton
    Mar 15 at 8:44
  • maybe, but whats strange is that i've used the same parameters as when i "manually" import the WFS layers (see the metadata source in the two pictures)
    – emanas
    Mar 16 at 1:15
  • The URL for the service should be just https://wxs.ign.fr/agriculture/geoportail/wfs? without the version. The GetCapabilities response has a error in it though reporting the URL as https://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).
    – nmtoken
    Mar 16 at 13:53
  • 1
    KVP parameters follow 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 is version=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
    – nmtoken
    Mar 16 at 14:01
  • 1
    The service IS slow, nothing to do with calling through QGIS, there are also a lot of features in RPG.2011:rpg_2011 (wxs.ign.fr/agriculture/geoportail/… gives 6170003 results), you'll need to use paging to get the results maybe 500 at a time 1000 at a time is default for QGIS desktop
    – nmtoken
    Mar 17 at 9:15


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.