gxo214

Changing Raster format and name with elif

Discussion created by gxo214 on Apr 15, 2014
Latest reply on Apr 15, 2014 by gxo214
Hello everyone,

my name is Giovanni and I am relatively new to ArcGIS and Python coding. I have a problem I haven't been able to solve: I have a large amount of .tif raster which I need to transform in .bil while at the same time changing their name. Both the input and output name have their own logic: input is equal to "australia_arcYYYYMMDD.tif" where YYYY is the year, MM the month and DD the day, output required is "rain_YYYYDDD.bil" where DDD is the Julian date, so that anyhow there will be a one-to-one relationship between the two.
I was trying something along the line of:
import arcpy 
arcpy.env.workspace = "e:/Pyton/prova/Tif" 
outLoc = ("e:/Pyton/prova/bil")
outDirectory = outLoc
datasetList = arcpy.ListDatasets("*", "Raster") 
for d in datasetList:
 tif = str(d)
 elif tif == "australia_arc20000101*":
  outRast = "rain_2000001.bil"
  outD = outDirectory + "/" + outRast
  arcpy.CopyRaster_management(tif,outD)
 elif tif == "australia_arc20000102*":
  outRast = "rain_2000002.bil"
  outD = outDirectory + "/" + outRast
  arcpy.CopyRaster_management(tif,outD)
 else:
  outRast = "rain_2000001.bil"
  outD = outDirectory + "/" + outRast
  arcpy.CopyRaster_management(tif,outD)


or otherwise
import arcpy 
arcpy.env.workspace = "E:/Pyton/Prova/Tif" 
outLoc = ("e:/Pyton/prova/bil")
outDirectory = outLoc
datasetList = arcpy.ListDatasets("*", "Raster") 
for d in datasetList:
 tif = str(d)
elif d in datasetlist == "australia_arc20000101*":
 outRast = "rain_2000001.bil"
 outD = outDirectory + "/" + outRast
 arcpy.CopyRaster_management(tif,outD)
elif d in datasetlist == "australia_arc20000102*":
 outRast = "rain_2000002.bil"
 outD = outDirectory + "/" + outRast
 arcpy.CopyRaster_management(tif,outD)
else:
 outRast = "rain_2000001.bil"
 outD = outDirectory + "/" + outRast
 arcpy.CopyRaster_management(tif,outD)


but neither of the two seems to work. As I've said I have little knowledge of the program (I'm a social scientist), so there might be some rookie error. The idea would be to write a long elif statement (365 elif + 1 else) once I got the proper way of doing it, is definitely not the most polished way of obtaining the result but the file are relatively small so that converting a year takes around ten minute. If anybody has any suggestion I am sure it will prove of invaluable help.
Thanks in advance

Giovanni

Outcomes