AnsweredAssumed Answered

Reading file at a time from a raster list using Python

Question asked by dljayasekera on Sep 12, 2017
Latest reply on Sep 12, 2017 by Dan_Patterson

HI,

 

Can somebody help me to read one file at a time in the following raster list? I want to match a condition and then read the corresponding raster file from the "rasterlist". My code below cannot achieve what I want.

 

Any help is appreciated.

 

Thanks in advance. 

 

year=2010
month=10
week=[1,2,3,4,5]

rasterlist = [
Week_1_Sum1981_10_Crawford.tif
Week_1_Sum1982_10_Crawford.tif
.
Week_1_Sum2016_10_Crawford.tif
Week_2_Sum1981_10_Crawford.tif
.
Week_2_Sum2016_10_Crawford.tif
.
Week_5_Sum2016_10_Crawford.tif]

for file in fmaskrasters:
  if fnmatch.fnmatch(file, 'Week_' + str(week) + '_Sum' + str(year) + '_' + str(month) + '_Crawford.tif'):
     print (file)

raster = rasterlist[file]

Outcomes