1

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

  • Are there are definitely shapefiles in C:\Users\uma.bhandaram\Desktop\2015\DailyMax2015\Shapefiles? – Fezter Nov 30 '16 at 3:20
  • @Fezter, yes there are. All I did was make a '2015' folder and move the 'Daily Max/Min folders' into it. – Uma Nov 30 '16 at 3:24
  • What happens if you print shpFileList before your for loop? What's in the list? My guess is that there is something there that shouldn't be. – Fezter Nov 30 '16 at 3:25
  • Does arcpy.Exists(env.workspace) return True? Usually, you need to put an r before windows filepath strings, so maybe try env.workspace = r"C:\Users\uma.bhandaram\Desktop\2015\DailyMax2015\Shapefiles" – KJYDavis Nov 30 '16 at 3:29
  • @KJYDavis, putting the 'r' before did the trick. So simple! Thank you! – Uma Nov 30 '16 at 3:33
2

You need to put an r (raw string) before windows filepath strings.

env.workspace = r"C:\Users\uma.bhandaram\Desktop\2015\DailyMax2015\Shapefile‌​s"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.