Is it possible to create a Virtual Layer through a python script. For example, I have a layer "road", and I would like to perform sql " SELECT * FROM road WHERE type = 'Expressway' "
Will this be possible? Is there any example i can refer to?
Answer
You could use something like the following:
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
vlayer = QgsVectorLayer( "?query=SELECT * FROM road WHERE type = 'Expressway'", "vlayer", "virtual" )
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
You can find examples on how to use virtual layers through python from the author's GitHub:
https://github.com/mhugo/qgis_vlayers/blob/master/README.md
No comments:
Post a Comment