3

I have a folder of shapefiles that I want to convert to rasters and then apply a Con statement to them. I set my workspace to where the shapefiles are and do Point to Raster conversion and Con with the following code:

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 = r"C:\Users\uma.bhandaram\Desktop\2015\DailyMax2015"
outputFolder = r"C:\Users\uma.bhandaram\Desktop\2015\RasterCon2015"

#Get Max 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, "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:
    rastFileName = os.path.splitext (rastFile) [0]
    MaxRstIn = Raster(rastFile)
    MaxRstOut = Con(MaxRstIn, 1, 0, "VALUE <=85")
    MaxRstOut.save("Con" + rastFile)

How do I save the output rasters of the Con function in a separate folder? I have specified an output folder but am stuck on pointing my Con files to go here.

4

You are never actually creating the complete output path to save the raster to. You need to use the variable you create initially outputFolder with os.path.join and the file name that you want and feed that into the .save() method. Like this:

output_raster_path = os.path.join(outputFolder, "Con" + rastFile)
MaxRstOut.save(output_raster_path)

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.