Question

So I've tried a few ways to search for my problem but nothing seems to give me the exact answer I am looking for. Here is my code for context:

# Import arcpy module
import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "F:\\dir"

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Local variable:
Inpoints = "F:\\dir\\x.shp"

fdata = "_01,_02,_03,_04,_05,_06,_07,_08,_09,_10,_11,_12"
fdata = fdata.split(",")

#initalizing the list
Inraster = []

#build list of inputs
   for year in range (1983, 2014):
     for line in fdata:
      date = str(year)+line
      Inraster1 = ["rfe"+date+".tif", date]

    Inraster.append(Inraster1)

# Process: Extract Multi Values to Points

arcpy.gp.ExtractMultiValuesToPoints_sa(Inpoints, Inraster, "NONE")

For the fdata line, I'd like it to read as or, so it doesn't search for every raster as some of the rasters in the ranges for various years don't exists (eg - month 1 1985 may exist but month 1 in 2003 does not).

Not sure if that makes sense?

(Notes: Using python 2.7)

Was it helpful?

Solution

import os

BASEDIR = "f:\\dir"

#build list of inputs
Inraster = []
for year in range (1983, 2014):
    for month in range(1, 13):
        fname = "ref{:04d}_{:02d}.tif".format(year, month)
        # is there actually a file by this name?
        if os.path.isfile(os.path.join(BASEDIR, fname)):
            Inraster.append(fname)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top