Geographic Information Systems Asked on June 8, 2021
I need an invalid layer to test a plugin in QGIS. In the plugin window, I select a layer from combobox. So, the invalid layer should be in Layers
panel. I google for a while but I cannot find a way to generate an invalid vector layer.
How can I generate one so that layer.isValid()
returns False
?
layer = QgsVectorLayer("zxcxzcxc/home/bera/GIS/Data/testdata/ak_riks.shp", "testlayer_shp", "ogr")
providerlib
that doesnt exist: layer = QgsVectorLayer("/home/bera/GIS/Data/testdata/ak_riks.shp", "testlayer_shp", "O G R")
, it should be "ogr"
Then add layer
to the project:
QgsProject.instance().addMapLayer(layer)
Correct answer by BERA on June 8, 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