vendredi 2 janvier 2015

Arcpy delete rasters in a folder


I'm working with rasters, there are 3 folder (input, query, result). In the input folder are the basic rasters. The user can choose between these rasters, the code can collect the rasters into the query folder, and after it will make a mean raster into the result folder. But after the second run i need to clear the query folder, because it stores the first run rasters and it gives a wrong result. How can i delete these rasters from the query folder, after every run?



import os, sys
import shutil
import arcpy
from arcpy import env
arcpy.CheckOutExtension("spatial")
from arcpy.sa import *
arcpy.env.overwriteOutput = True
start_date = arcpy.GetParameterAsText(0)
end_date = arcpy.GetParameterAsText(1)
env.workspace = "c:/temperature/input"
rasters = arcpy.ListRasters("*","GRID")
for raster in rasters:
if int(raster) >= int(start_date) and int(raster) <= int(end_date):
arcpy.CopyRaster_management((raster), "c:/temperature/query/" + (raster) + ".tif", "", "", "", "NONE", "NONE", "", "NONE", "NONE")
env.workspace = "c:/temperature/query"
eredmeny = "c:/temperature/result/mean.tif"
rasterses = arcpy.ListRasters("*","TIF")
result = arcpy.gp.CellStatistics_sa((rasterses), result, "MEAN", "DATA")
exit()




Aucun commentaire:

Enregistrer un commentaire