I've written the following code to process files within 2 separate folders, 'Daily Max 2015' and 'Daily Min 2015'. The workspace is set to: "C:\Users\uma.bhandaram\Desktop\DailyMax2015\Shapefiles". With this, the code works.
import arcpy
import os
from arcpy import env
from arcpy.sa import *
#Set workspace to Max Temps folder and allow for overwrite
env.overwriteOutput = True
env.workspace = "C:\Users\uma.bhandaram\Desktop\DailyMax2015\Shapefiles"
#Get Max Temp shapefiles and convert them to Raster
shpFileList = arcpy.ListFiles("*.shp")
for shpFile in shpFileList:
# geoprocessing steps
shpFileName = os.path.splitext (shpFile)[0]
rastFile = shpFileName + ".tif"
arcpy.PointToRaster_conversion(shpFile, "Max_2015", rastFile, "MOST_FREQUENT", "", 0.05)
#Get raster files and run through Raster Calculator to see if Max threshold has been met
rastFileList = arcpy.ListFiles("*.tif")
for rastFile in rastFileList:
#geoprocessing steps
rastFileName = os.path.splitext (rastFile) [0]
MaxRstIn = Raster(rastFile)
MaxRstOut = Con(MaxRstIn, 1, 0, "VALUE <=85")
MaxRstOut.save("Con" + rastFile)
#Set workspace to Min Temps folder and allow overwrite
env.overwriteOutput = True
env.workspace = "C:\Users\uma.bhandaram\Desktop\DailyMin2015"
#Loop through Min Temp shapefiles and convert them to Raster
shpFileList = arcpy.ListFiles("*.shp")
for shpFile in shpFileList:
shpFileName = os.path.splitext (shpFile)[0]
rastFile = shpFileName + ".tif"
arcpy.PointToRaster_conversion(shpFile, "Min_2015", rastFile, "MOST_FREQUENT", "", 0.05)
#Loop through raster files and run through Raster Calculator to see if Min threshold has been met
rastFileList = arcpy.ListFiles("*.tif")
for rastFile in rastFileList:
rastFileName = os.path.splitext (rastFile) [0]
MinRstIn = Raster(rastFile)
MinRstOut = Con(MinRstIn, 1, 0, "VALUE >=45")
MinRstOut.save("Con" + rastFile)
I need to find the sum of the each corresponding Daily Max and Daily Min file so I brought them together in a '2015' file and run Cell Statistics. Accordingly, I changed the workspace to: "C:\Users\uma.bhandaram\Desktop\2015\DailyMax2015\Shapefiles"
import arcpy
import os
from arcpy import env
from arcpy.sa import *
#Set workspace to Max Temps folder and allow for overwrite
env.overwriteOutput = True
env.workspace = "C:\Users\uma.bhandaram\Desktop\2015\DailyMax2015\Shapefiles"
#Get Max Temp shapefiles and convert them to Raster
shpFileList = arcpy.ListFiles("*.shp")
for shpFile in shpFileList:
# geoprocessing steps
shpFileName = os.path.splitext (shpFile)[0]
rastFile = shpFileName + ".tif"
arcpy.PointToRaster_conversion(shpFile, "Max_2015", rastFile, "MOST_FREQUENT", "", 0.05)
#Get raster files and run through Raster Calculator to see if Max threshold has been met
rastFileList = arcpy.ListFiles("*.tif")
for rastFile in rastFileList:
#geoprocessing steps
rastFileName = os.path.splitext (rastFile) [0]
MaxRstIn = Raster(rastFile)
MaxRstOut = Con(MaxRstIn, 1, 0, "VALUE <=85")
MaxRstOut.save("Con" + rastFile)
#Set workspace to Min Temps folder and allow overwrite
env.overwriteOutput = True
env.workspace = "C:\Users\uma.bhandaram\Desktop\2015\DailyMin2015"
#Loop through Min Temp shapefiles and convert them to Raster
shpFileList = arcpy.ListFiles("*.shp")
for shpFile in shpFileList:
shpFileName = os.path.splitext (shpFile)[0]
rastFile = shpFileName + ".tif"
arcpy.PointToRaster_conversion(shpFile, "Min_2015", rastFile, "MOST_FREQUENT", "", 0.05)
#Loop through raster files and run through Raster Calculator to see if Min threshold has been met
rastFileList = arcpy.ListFiles("*.tif")
for rastFile in rastFileList:
rastFileName = os.path.splitext (rastFile) [0]
MinRstIn = Raster(rastFile)
MinRstOut = Con(MinRstIn, 1, 0, "VALUE >=45")
MinRstOut.save("Con" + rastFile)
But, with this one change, I get the following error:
Traceback (most recent call last):
File "C:\Users\uma.bhandaram\Desktop\Python\Script3.py", line 12, in
for shpFile in shpFileList:
TypeError: 'NoneType' object is not iterable
The data are there - any thoughts on why this error? I'm working with Python 2.7 and ArcGIS 10.3
Much thanks.