Listing Rasters - finds the raster, then tells me it doesn't exist - which it does

المشرف العام

Administrator
طاقم الإدارة
Hey so I'm trying to do some geoprocessing with Arcpy and I am using the ListRasters function and it says in the output that it finds the rasters but then tells me the input raster does not exist (which I confirmed that it did).

This is my entire code:

Import modulesimport arcpyfrom arcpy.sa import *from arcpy import envimport string, glob, osfrom glob import globimport sys, tarfileimport itertoolsimport tracebackfrom itertools import izipimport math, fnmatchimport shutil, datetimeimport subprocessfrom subprocess import Popen, PIPE#Set environmentarcpy.CheckOutExtension("spatial")arcpy.env.overwriteOutput = Trueenv.extent = "MINOF"env.cellSize = "MINOF"Coordsystem = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"#Enter Input datainputpath = r"G:\CFactor Processing"yearvalue = raw_input("Enter Year of data to process: ")year = str(yearvalue)directory = inputpath + "\\" + year#Output folder##outputfolder = raw_input("Enter output folder directory: ")outputfolder = directory + "\\" + "tdiffstats"if not os.path.exists(outputfolder): os.mkdir(outputfolder)#Create scratch folderscratch_folder = outputfolder + "\\" + "scratch"if not os.path.exists(scratch_folder): os.mkdir(scratch_folder)#Establish Input datapathrow = raw_input("Enter filepath to shapefile: ") #Path38Row37 boundary shapefileTdiff_folder = directory + "\\" + "Tdiff"Tcorr_folder = directory + "\\" + "Tcorr"env.workspace = Tdiff_folderTdiff_folder = directory + "\\" + "Tdiff"Tdiffrasters = arcpy.ListRasters()Tdiffrasters.sort()print "Tdiff rasters found"env.workspace = Tcorr_folderTcorr_folder = directory + "\\" + "Tcorr"Tcorrrasters = arcpy.ListRasters()Tcorrrasters.sort()print "Tcorr rasters found"for Tdiff in Tdiffrasters: Jdate = str(Tdiff[-7:-4]) print 'Jdate is ' + str(Jdate) env.workspace = Tdiff_folder Tdiff = arcpy.ListRasters("*" + year + Jdate + "*","All")[0] env.workspace = Tcorr_folder Tcorr = arcpy.ListRasters("tcorr" + year + Jdate + "*","All")[0] #Find Inputs filename = Jdate scenedate = year + Jdate if Tdiff[-7:-4]==filename and Tcorr[-7:-4]: Tdiffrasters = Raster(Tdiff_folder + "\\" + Tdiff) Tcorrrasters = Raster(Tcorr_folder + "\\" + Tcorr) print "inputs found" #Environment settings arcpy.CheckOutExtension("spatial") arcpy.env.overwriteOutput = True env.extent = "MINOF" env.cellSize = "MINOF" Coordsystem = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]" #Clip Tdiff by Tcorr Tdiffcl = scratch_folder + "\\" + "tdiffcl" + Jdate arcpy.gp.ExtractByMask_sa(Tdiff,Tcorr,Tdiffcl) Tdiffc = scratch_folder + "\\" + "Tdiffc" + Jdate arcpy.gp.ExtractByMask_sa(Tdiffcl,pathrow,Tdiffc) print "Tdiff is clipped" #Convert Tdiff to Integer Tdiff_int = Int(Tdiffc) Tdiff_path = outputfolder + "\\" + "Tdiff" if not os.path.exists(Tdiff_path): os.mkdir(Tdiff_path) arcpy.CopyRaster_management(Tdiff_int,Tdiff_path + "\\" + "Tdiff_i" + Jdate) print "Converted to Integer" #Get zonal mean and save to excel output = outputfolder + "\\" + "zonal" if not os.path.exists(output): os.mkdir(output) outTable = output + "\\" + "tdiff" + Jdate + ".dbf" print outTable outZstat = ZonalStatisticsAsTable(pathrow,"FID",Tdiff_int,outTable,"DATA","ALL") print "zonalstat done" output2 = outputfolder + "\\" + "Tdiffstat" if not os.path.exists(output2): os.mkdir(output2) outExcel = output2 + "\\" + outTable[-16:-4] + ".xls" print outExcel arcpy.TableToExcel_conversion(outTable,outExcel) print "xls created"print "done!"I get the following error message:

Tdiff rasters foundTcorr rasters foundJdate is 010inputs foundTraceback (most recent call last): File "C:\Python27\ArcGIS10.3\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScriptexec codeObject in __main__.__dict__ File "C:\Users\mschauer\Documents\Py Scripts\Tdiff_stats.py", line 102, in arcpy.gp.ExtractByMask_sa(Tdiff,Tcorr,Tdiffcl) File "C:\ArcGIS\Desktop10.3\ArcPy\arcpy\geoprocessing\_base.py", line 504, in return lambda *args: val(*gp_fixargs(args, True))ExecuteError: Failed to execute. Parameters are not valid.ERROR 000865: Input raster: tdiff1999010.tif does not exist.Failed to execute (ExtractByMask).I don't know what I am doing wrong or how to get the code to recognize the raster file and actually use it for what I want. I'm using ArcgiS 10.3.1 with Python 2.7.8 on a Window 7 machine through PythonWin IDE (I also used IDLE and got the same error).



أكثر...
 
أعلى