5

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:

enter image description here

0

1 Answer 1

4

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

result

Your Answer

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

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