1

I am using QGIS 3.2.0 and want to use PyQGIS to load WMS services to the layout and output the layout and end up with a PNG image. The problem is with the legend, which is not showing on the map.

Using WMS services http://127.0.0.1:8002/geoserver/yqycxt/wms?service=WMS&version=1.1.0&request=GetCapabilities

The result of loading in the software is as follows

enter image description here

I load it in this way:

project = QgsProject.instance()
urlWithParams = "crs=EPSG:4326&dpiMode=7&format=image/png&layers=jizhen&url=http://127.0.0.1:8002/geoserver/yqycxt/wms?service=WMS&version=1.1.0&username=username&password=password&contextualWMSLegend=1&styles"
# Used contextualWMSLegend=1
rlayer = QgsRasterLayer(urlWithParams, 'test_wms_legend_load', 'wms')
if rlayer.isValid():
    project.addMapLayer(rlayer, addToLegend=True)

Referenced:

But the results do not contain the WMS legend.

Loading WMS in the software, the legend is valid.

enter image description here

0

Your Answer

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

Browse other questions tagged or ask your own question.