I'd like to add a WMS layer through my QGIS plugin with custom CQL_FILTER parameters. My problem is, that the CQL_FILTER parameters are not passed to the GeoServer (I can see it in the GeoServer log at the GetMap query: "CQLFilter = null").

This is what I've tried:

registry = QgsMapLayerRegistry.instance()    
urlWithParams = "cql_filter=BBOX(geom, 579465,125671,664692,167717)&crs=EPSG:23700&featureCount=10&format=image/png&layers=master&styles=&url=http://localhost:9090/geoserver/myWorkspace/wms"
rlayer = QgsRasterLayer (urlWithParams , "my_title", "wms")

The WMS layer is added to the map with no problem, but all the features are visible on the layer even outside the BBOX I defined in the parameters. When I use the GeoServer's built-in CQL_FILTER builder (with the layer preview) the same filter works as desired.

Does anyone have a solution or a workaround for this?

I use QGIS 2.4.0-Chugiak.

1 Answer 1


if you are using PyQgis 2.x

 registry = QgsMapLayerRegistry.instance() urlWithParams =
 579465,125671,664692,167717)" rlayer = QgsRasterLayer (urlWithParams
 , "my_parcels", "wms") registry.addMapLayer(rlayer)

if you are using PyQgis 3.x

urlWithParams = "contextualWMSLegend=0&IgnoreGetMapUrl=1&crs=EPSG:32643&dpiMode=7&featureCount=10&format=image/png&layers=bldg&styles&url=http://localhost:8080/geoserver/Testing/wms%3FCQL_FILTER=BBOX(geom, 579465,125671,664692,167717)"
vLayer = QgsRasterLayer(urlWithParams, 'Output', 'wms')

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.