Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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() )

Or if by chance you want to remove all empty layers, check out the Remove Empty Layers plugin.

share|improve this answer
    
thanks for the answer.. I'll try as soon as possible –  Heisenbug Nov 27 '12 at 18:29
    
ok -- note that I just edited the answer to use your vl variable. –  andytilia Nov 27 '12 at 18:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.