I add a TileMapService layer to QGIS map window using a Python console. But added layer is not displayed. What is wrong?
tmsLayer_name = 'YandexSat'
uri = "url=http://sat04.maps.yandex.net/tiles?l=sat&x={x}&y={y}&z={z}&zmax=19&zmin=0&type=xyz"
tms_layer = QgsRasterLayer(uri,tmsLayer_name,'wms')
if not tms_layer.isValid():
print ("Layer failed to load!")
else:
QgsProject.instance().addMapLayer(tms_layer)
At the same time QMS perfectly displays the same layer:
-
Please, do not forget about "What should I do when someone answers my question?"Taras– Taras ♦2024年08月16日 08:48:42 +00:00Commented Aug 16, 2024 at 8:48
1 Answer 1
The uri
looks good:
uri = "url=http://sat04.maps.yandex.net/tiles?l=sat&x={x}&y={y}&z={z}&zmax=19&zmin=0&type=xyz"
but in certain places it requires the percent-encoding.
As soon as you convert the uri
into:
uri = "url=http://sat04.maps.yandex.net/tiles?l%3Dsat%26x%3D%7Bx%7D%26y%3D%7By%7D%26z%3D%7Bz%7D&zmax=19&zmin=0&type=xyz"
where:
%3D <=> =
%26 <=> &
%7B <=> {
%7D <=> }
it should work, see image below
answered Nov 25, 2021 at 8:02
Explore related questions
See similar questions with these tags.
lang-py