Friday, 2 October 2015

pyqgis - Deleting raster file after doing some processing in QGIS?


I run this script in my python console on QGIS:


import os
import processing
from qgis.core import QgsVectorLayer

polygon_file = "E:/polygon.shp"
point_input = "E:/station.shp"

raster_output = 'E:/output_idw.tif'

layer = QgsVectorLayer(point_input, 'layer', 'ogr')
processing.runalg('grass7:v.surf.idw', layer, 8.0, 5.0, 'value', False, "%f,%f,%f,%f" % (110.5, 117, -9, -4.5), 0.001, -1.0, 0.0001, raster_output)
processing.runalg("gdalogr:cliprasterbymasklayer", raster_output, polygon_file, -1, False, False, False, 6, 0, 75, 1, 1, False, 0, False, "", 'E:/output_crop.tif')
os.remove(raster_output)

I need to delete the unclip raster file (raster_output) directly by doing "os.remove(raster_output)" after processing but it return "[Error 32] The process cannot access the file because it is being used by another process" What should i do so i can delete that file without exit QGIS?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...