3

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")
registry.addMapLayer(rlayer)

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.

0

if you are using PyQgis 2.x

 registry = QgsMapLayerRegistry.instance() urlWithParams =
 "crs=EPSG:21037&IgnoreGetMapUrl=1&featureCount=10&format=image/png&styles=&layers=parcels&url=http://localhost:8060/geoserver/cadastralWsp/wms%3FCQL_FILTER=BBOX(geom,
 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')
QgsProject.instance().addMapLayer(vLayer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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