Geographic Information Systems Asked on June 6, 2021
canvas = QgsMapCanvas()
canvas.show()
canvas.setCanvasColor(Qt.white)
canvas.enableAntiAliasing(True)
vlayer = QgsVectorLayer('testdata/airports.shp', "Airports layer", "ogr")
canvas.setExtent(vlayer.extent())
canvas.setLayers([vlayer])
tms = 'type=xyz&url=https://tile.openstreetmap.org/{z}/{x}/{y}.png&zmax=19&zmin=0'
layer = QgsRasterLayer(tms,'OSM', 'wms')
canvas.setLayers([layer ])
Above code works fine with vector layer but when I am trying to QgsRasterLayer
show cyan colour.
How can I add raster layer on map canvas?
That cyan color is probably The Atlantic Ocean. Try the following way. It worked for me.
test_data = 'testdata/airports.shp'
canvas = QgsMapCanvas()
vlayer = QgsVectorLayer(test_data, "test", "ogr")
canvas.setCanvasColor(Qt.white)
canvas.enableAntiAliasing(True)
tms = 'type=xyz&url=https://tile.openstreetmap.org/{z}/{x}/{y}.png&zmax=19&zmin=0'
layer = QgsRasterLayer(tms,'OSM', 'wms')
canvas.setLayers([vlayer, layer])
canvas.setExtent(vlayer.extent())
canvas.show()
Correct answer by Kadir Şahbaz on June 6, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP