Closing QgsRasterLayer's file handler in Python script

Geographic Information Systems Asked by Edgar Szilagyi on December 2, 2020

I’m creating a QgsRasterLayer from temporary file, as result from some processing algorithm.

After that, I no longer can delete file, as expected. But, because It is only a temp file, I need delete It after all my processing is done.

I tried, without success:

layer = QgsRasterLayer("myTempFile.tif")

#Do some work...

del layer

myTempFile.tif still can’t be deleted, but only after closing QGIS.

One Answer

Here is a similar thread which you can also read: Removing a vector layer from QGIS

Try something like this, you will need to adapt it to reflect the layer(s) you are working with.

layer = QgsRasterLayer('path/to/your/raster.tif')

#do the rest of your code


Answered by Erich Purpur on December 2, 2020

Add your own answers!

Related Questions

Adding vertex into polyline at interval using ArcPy

1  Asked on June 15, 2021 by preethi-r


Nearest Neighbor

2  Asked on June 15, 2021 by cokrzys


QGIS 3.10.4-A Coruña overload?

0  Asked on June 15, 2021 by projekt-celt


SAR GRD preprocessing workflow necessity

0  Asked on June 14, 2021 by ashwin-nair


Calculating NDVI-Analyzing Results

0  Asked on June 14, 2021


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir