Skip to main content
edited body; edited title
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

How to load wms Loading WMS service to display wmsWMS legend when exporting map layout

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

Using wmsWMS 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 wmsWMS legend.

Loading wmsWMS in the software, the legend is valid.

enter image description here

How to load wms service to display wms legend when exporting map layout

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

Loading WMS service to display WMS legend when exporting map layout

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

added 1 character in body
Source Link

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

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"
# 使用了 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

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

Source Link

How to load wms service to display wms legend when exporting map layout

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"
# 使用了 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