I'm using very big memory layers:
Is there any way to empty (fast), destroy or clean a layer in memory from an script without exit from this script ?
xunilk
30.5k4 gold badges44 silver badges83 bronze badges
asked Dec 7, 2016 at 19:23
-
Perhaps this post might help: Deleting all Features of a Vector Layer in pyQGIS. I don't see why the solution to that post shouldn't work for memory layers.Joseph– Joseph2016年12月08日 11:09:49 +00:00Commented Dec 8, 2016 at 11:09
-
1Thanks, Joseph, The solutions discussed in the link you comment are the closest to what I thought. Looking at the sources of QGIS (and GDAL / OGR) I have seen that there is no method like: layer.empy () or similarJuanma Font– Juanma Font2016年12月09日 08:13:58 +00:00Commented Dec 9, 2016 at 8:13
2 Answers 2
Have you tried
del(layer)
These should remove the reference to the layer and call the layer destructor.
In your script you can use:
QgsMapLayerRegistry.instance().removeMapLayer(mem_layer.id())
assuming that the name of memory layer is 'mem_layer'.
answered Dec 7, 2016 at 22:37
-
You have to add the layer to the registry in order to remove it (and delete it) in this case. If you are just working with arrays in memory then you want to delete the handle without adding it to the registry (saving time).A.A– A.A2016年12月08日 11:32:18 +00:00Commented Dec 8, 2016 at 11:32
lang-py