Skip to main content
Bounty Ended with 50 reputation awarded by axel_ande
added 9 characters in body
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

Tiles/WMS sources aregive you raster data. YouSo, you have to use QgsRasterLayer() instead of QgsVectorLayer().

Try in this way:

...
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms') # EDIT THIS LINE

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

Tiles/WMS sources are raster data. You have to use QgsRasterLayer() instead of QgsVectorLayer().

Try in this way:

...
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms') # EDIT THIS LINE

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

Tiles/WMS sources give you raster data. So, you have to use QgsRasterLayer() instead of QgsVectorLayer().

Try in this way:

...
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms') # EDIT THIS LINE

    if rlayer.isValid():
        QgsProject.instance().addMapLayer(rlayer)
    else:
        print('invalid layer')
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

Tiles/WMS sources are raster data. You have to use QgsRasterLayer() instead of QgsVectorLayer().

Try in this way:

...
    rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms') # EDIT THIS LINE

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