4

I've created a layer in GeoServer. The layer is based on a SQL view and is parametrized as described in the documentation. I can access the WFS in the browser with a URL something like the below:

http://localhost:8080/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=cite:mylayer&maxFeatures=50&outputFormat=application%2Fjson&viewparams=myuuid:2a18bb306af24e29a8f1a40f80229749;myyear:2016

(Note the viewparams part at the end of the query string.)

But I don't see a way to set these parameters in QGIS when I'm adding the layer. I can connect successfully and find my layer in the list, but there doesn't seem to be a way to configure these parameters:

Add WFS Layer dialog

How can I set these parameters? Does the Build query functionality allow me to via some mechanism I'm not aware of?

2
  • You can try to create the WFS connection so that the base URL contains the view parameter http://localhost:8080/geoserver/wfs?VIEW_PARAM=my_param&. This may work if QGIS does not use the GetFeature URL that comes with the GetCapabilities. Even if it happens to work you can't make it dynamic but you must create a new connection for each VIEW_PARAM value that you will need.
    – user30184
    Aug 27, 2016 at 13:39
  • this is reported here: issues.qgis.org/issues/6354
    – Lennert
    Oct 19, 2018 at 8:34

1 Answer 1

-1

with python 2.x in Qgis 2.14.x and 2.18.x, you can use params in url like this:

uri='http://path/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=workspace:layer&SRSNAME=EPSG:xxx&viewParams=param1:valueparam' 
layer = QgsVectorLayer(uri, "layer_wfs_with_params", "WFS")
if not layer.isValid():
    print "Layer failed to load!"
else:
    QgsMapLayerRegistry.instance().addMapLayer(layer)

in qgis 3.x, with python 3.x

import urllib
params ={
    'service':'WFS',
    'version':'1.1.0',
    'request':'GetFeature',
    'typename':'somelayer',
    'srsname':"EPSG:xxx",
    'user':'a',
    'password':'',
   # 'cql_filter':cql_filter,
    'viewParams':"param1:valueparam"
}
uri="http://path/wfs?'+urllib.parse.unquote(urllib.parse.urlencode(params))

layer= QgsVectorLayer(uri, 'layer_wfs_with_params',"WFS")
if not layer.isValid():
    print ("Layer failed to load!")
else:
    QgsProject.instance().addMapLayer(layer)

bye.

1
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. A good answer should include not only what to do, but also how to do it. Please edit your answer to include an explanation about how to use your suggested solution, and what it does.
    – Midavalo
    May 24, 2017 at 14:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.