Hi Raymond,

I first tested in 2.18.1, and that one just worked, no matter how many times. Also the saving/opening of the project.

Then I went to a 2.14.7 version I have, and then one FAILED. In the debug information (you run debug version from cli don't you ;-) ) I found:
DescribFeatureType Failed
Googling that I found 'qgis wfs DescribFeatureType Failed' I found:

http://gis.stackexchange.com/questions/205926/qgis-2-16-adding-certain-wfs-failed

which actually talks about exact the same service! Pointing to:
http://hub.qgis.org/issues/15395
which says:
Fixed per 4bcbc1e (and backported in master_2 in f17f6ac, and in release-2_16 a0e3e76)

pointing to this commit:

https://github.com/qgis/QGIS/commit/4bcbc1e4e7ce89237e48067e352d50079fdfa4a6

which looks like it had to handle an uncommon capabilities construct from the ruimtelijkeplannen.nl service ....

So I think 2.14 is not patched? You need to have latest 2.18 or 2.16 ...

maybe Even can comment on this? Is it possible to bring this fix in 2.14 (LTR?)

Regards,

Richard Duivenvoorde



On 12/10/2016 01:53 PM, Raymond Nijssen wrote:
import urllib
#from qgis.core import import
import time

plangebied = 'NL.IMRO.0796.0002120-1301'

'''
params = {
    'service': 'WFS',
    'version': '1.0.0',
    'request': 'GetFeature',
    'typename': 'union',
    'srsname': "EPSG:23030"
}
'''


def getWfsLayer(service, typename, filter):
    params = {
        'typename': typename,
        'filter': filter,
        'srsname': 'EPSG:28992',
        #'restrictToRequestBBOX': '1',
        #'version': '2.0.0',
        #'table': '',
        #'sql': ''
    }
    if not service[-1] == '?':
        service += '?'
    uri = service + urllib.unquote(urllib.urlencode(params))
    #print uri
    layername = typename
    vlayer = QgsVectorLayer(uri, layername, "WFS")
    return vlayer


def addBestemmingsplan(plangebied):
    service = 'http://afnemers.ruimtelijkeplannen.nl/afnemers2012/services'
    filter = '"plangebied"=\'' + plangebied + '\''
    #print(filter)
    layers = [ \
        'app:Bouwaanduiding', \
        'app:Bouwvlak', \
        'app:Enkelbestemming', \
        'app:Bestemmingsplangebied', \
    ]

    root = QgsProject.instance().layerTreeRoot()
    bpName = plangebied
    bpGroup = root.insertGroup(0, bpName)
    #print bpGroup

    for layer in layers:
        #time.sleep(1)
        print layer
        vlayer = getWfsLayer(service, layer, filter)
        print vlayer
        #vlayer.updateExtents()
        if vlayer.isValid():
            QgsMapLayerRegistry.instance().addMapLayer(vlayer, False)
            #time.sleep(1)
            node_vlayer = bpGroup.addLayer(vlayer)
            #time.sleep(1)
        else:
            print 'invalid layer'

    canvas = iface.mapCanvas()
    canvas.refresh()


addBestemmingsplan(plangebied)

_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to