Considering my program is generating a shapefile that has to be added to the "Layers" tab in QGIS interface. However, once the utility of the layer is completed, I need to remove the layer in the middle of the code. I want to remove only the active layer and not all.
To put it in easier words, is there an opposite to self.iface.addVectorLayer()
?
Answer
This question may be seen as a duplicate with this post, in which case I will happily remove my answer.
The solution, provided by @andytilia, involves using the following command for versions of QGIS from 1.8 to 2.99.
QgsMapLayerRegistry.instance().removeMapLayers( [vl.id()] )
The solution involves using the following command for QGIS 3.X.
QgsProject.instance().removeMapLayers( [vl.id()] )
No comments:
Post a Comment