2

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
2
  • 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. Commented Dec 8, 2016 at 11:09
  • 1
    Thanks, 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 similar Commented Dec 9, 2016 at 8:13

2 Answers 2

4

Have you tried

del(layer)

These should remove the reference to the layer and call the layer destructor.

answered Dec 7, 2016 at 21:15
3

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
1
  • 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). Commented Dec 8, 2016 at 11:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.