Skip to main content
Rollback to Revision 1
Source Link
ncica
  • 942
  • 5
  • 17

Here is the code which is working for me:

    urlWithParams = 'type=xyz&url=https://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857'
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')  

    if rlayer.isValid():
        QgsProject.instance().addMapLayer(rlayer)
    else:
        print('invalid layer')

and result is:

Exampleenter image description here

like in an old discussion: Adding a Tiles/wms? (openStreetMap) layer with python in QGIS

Here is the code which is working for me:

urlWithParams = 'type=xyz&url=https://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857'
rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')  

if rlayer.isValid():
   QgsProject.instance().addMapLayer(rlayer)
else:
   print('invalid layer')

and result is:

Example

like in an old discussion: Adding a Tiles/wms? (openStreetMap) layer with python in QGIS

Here is the code which is working for me:

    urlWithParams = 'type=xyz&url=https://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857'
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')  

    if rlayer.isValid():
        QgsProject.instance().addMapLayer(rlayer)
    else:
        print('invalid layer')

and result is:

enter image description here

like in an old discussion: Adding a Tiles/wms? (openStreetMap) layer with python in QGIS

Tiny adjustments
Source Link
Taras
  • 34.1k
  • 4
  • 73
  • 148

Here is the code which is working for me:

    urlWithParams = 'type=xyz&url=https://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857'
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')  

    if rlayer.isValid():
        QgsProject.instance().addMapLayer(rlayer)
    else:
        print('invalid layer')

and result is:

enter image description hereExample

like in an old discussion: Adding a Tiles/wms? (openStreetMap) layer with python in QGIS

Here is the code which is working for me:

    urlWithParams = 'type=xyz&url=https://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857'
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')  

    if rlayer.isValid():
        QgsProject.instance().addMapLayer(rlayer)
    else:
        print('invalid layer')

and result is:

enter image description here

like in an old discussion: Adding a Tiles/wms? (openStreetMap) layer with python in QGIS

Here is the code which is working for me:

urlWithParams = 'type=xyz&url=https://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857'
rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')  

if rlayer.isValid():
   QgsProject.instance().addMapLayer(rlayer)
else:
   print('invalid layer')

and result is:

Example

like in an old discussion: Adding a Tiles/wms? (openStreetMap) layer with python in QGIS

Source Link
ncica
  • 942
  • 5
  • 17

Here is the code which is working for me:

    urlWithParams = 'type=xyz&url=https://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857'
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms')  

    if rlayer.isValid():
        QgsProject.instance().addMapLayer(rlayer)
    else:
        print('invalid layer')

and result is:

enter image description here

like in an old discussion: Adding a Tiles/wms? (openStreetMap) layer with python in QGIS