I managed to add QgsVectorLayer
in QGIS
through a python plugin, for example:
vl = self.iface.addVectorLayer(uri.uri(), layerName, self.dbConn.getProviderName())
But how can I remove it?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI managed to add QgsVectorLayer
in QGIS
through a python plugin, for example:
vl = self.iface.addVectorLayer(uri.uri(), layerName, self.dbConn.getProviderName())
But how can I remove it?
Are you on QGIS 1.8? If so, you can remove your vl
with:
QgsMapLayerRegistry.instance().removeMapLayers( [vl.id()] )
otherwise:
QgsMapLayerRegistry.instance().removeMapLayer( vl.id() )
And if you are on QGIS 3.0+, replace QgsMapLayerRegistry
with QgsProject
.
Or if by chance you want to remove all empty layers, check out the Remove Empty Layers plugin.