Last active
January 28, 2021 00:07
-
-
Save ThomasG77/82384d44a10ac7a4844c39ff8035612a to your computer and use it in GitHub Desktop.
PyQGIS add WMS layer standalone sample (use capabilities listing from owslib)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PyQGIS add WMS layer standalone sample | |
# Before use owslib library (bundled in QGIS) to list WMS layers in capabilities | |
from owslib.wms import WebMapService | |
url = 'https://www.gebco.net/data_and_products/gebco_web_services/2020/mapserv' | |
wms = WebMapService(url, version='1.3.0') | |
for name, metadata in wms.contents.items(): | |
print(name) | |
urlWithParams = 'url={}&crs=EPSG:4326&format=image/png&layers=GEBCO_2020_Grid&styles='.format(url) | |
rlayer = QgsRasterLayer(urlWithParams, 'some layer name', 'wms') | |
if not rlayer.isValid(): | |
print("Layer failed to load!") | |
QgsProject.instance().addMapLayer(rlayer) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment