I created a script in which I run numerous algorithms from processing
. Each resulting layer is stored in a shp
file. I just want to keep the final layer and delete the others, but when I want to erase them while QGIS is still open, they are still in usewhile not shown in the layers list, I can't erase them. This is a problem when I run my script a 2nd time because it doesn't work.
I tried removing the layers with
QgsMapLayerRegistry.instance().addMapLayer(layer)
QgsMapLayerRegistry.instance().removeMapLayer(layer.id())
but I had no success so far...
.prj .qpj
and .shx
are deleted, only remains .dbf
and .shp
.
Here is the code
import processing
from qgis.core import *
layer=processing.getObject("carte")
layer.invertSelection()
processing.runalg('qgis:fixeddistancebuffer', layer, "20","5",False, "c:/Users/LENOVO/Desktop/zones/tampon+.shp")
processing.runalg('qgis:dissolve', "c:/Users/LENOVO/Desktop/zones/tampon+.shp", True, None, "c:/Users/LENOVO/Desktop/zones/dissolve.shp")
tampon=QgsVectorLayer("c:/Users/LENOVO/Desktop/zones/tampon+.shp", 'finale','ogr')
QgsMapLayerRegistry.instance().addMapLayer(tampon)
QgsMapLayerRegistry.instance().removeMapLayer(tampon.id())
processing.runalg('qgis:fixeddistancebuffer', "c:/Users/LENOVO/Desktop/zones/dissolve.shp", "-20","5",False, "c:/Users/LENOVO/Desktop/zones/carte_finale.shp")
dissolve=QgsVectorLayer("c:/Users/LENOVO/Desktop/zones/dissolve.shp", 'finale','ogr')
QgsMapLayerRegistry.instance().addMapLayer(dissolve)
QgsMapLayerRegistry.instance().removeMapLayer(dissolve.id())
layer = QgsVectorLayer("c:/Users/LENOVO/Desktop/zones/carte_finale.shp", 'finale','ogr')
QgsMapLayerRegistry.instance().addMapLayer(layer)
{}
formatting button on your code. The backlick is on intended for individual words.