1

I have written the following code to convert my point files of daily max temps to rasters:

# Set local variables for Point to Raster Conversion
inFeatures = Day12015Max
valField = "Max_2015"
outRaster = ("Rstr12015Max")
assignmentType = "MOST_FREQUENT"
priorityField = ""
cellSize = 0.05

# Point to Raster conversion for Max values
arcpy.PointToRaster_conversion(inFeatures, valField, outRaster, assignmentType, priorityField, cellSize)

I have years worth of data so this will be 365x files to process. If all my point files are in a folder, how can I write a script that will go into the folder and go down the list and convert everything and output to a new folder?

I am working with Python 2.7 and ArcGIS 10.3

I have tried the following method:

env.workspace = "C:\Users\uma.bhandaram\Desktop\DailyMax2015\Shapefiles"

#folder to list
shpFileList = arcpy.ListFiles("*.shp")

for shpFile in shpFileList:
    # geoprocessing steps
    shpFileName = os.path.splitext (shpFile)[0]
    rastFile = shpFileName + "Rast.tif"

arcpy.PointToRaster_conversion(shpFile, "Max_2015", rastFile, "MOST_FREQUENT", "", 0.05)

But, this only processes one file and does not seem to loop through.

  • I'm voting to close this question as off-topic because it's show zero research effort. – John Powell Nov 29 '16 at 17:21
  • @JohnBarça, just edited to include what I have tried so far. Sorry, I am very new and really have no idea where to even start. – Uma Nov 29 '16 at 17:32
  • OK, apologies. Being new is fine :-). You just need to show what you have tried and where it went wrong. – John Powell Nov 29 '16 at 17:33
  • rastFile = shp + "rast" --> this becomes myfile.shprast – Paul Nov 29 '16 at 17:42
  • 1
    You need to indent the line calling PointToRaster so it's inside the loop. – phloem Nov 29 '16 at 18:22
3

As noted in the comments, you need to indent the line calling PointToRaster to include it within the loop.

env.workspace = "C:\Users\uma.bhandaram\Desktop\DailyMax2015\Shapefiles"

#folder to list
shpFileList = arcpy.ListFiles("*.shp")

for shpFile in shpFileList:
    # geoprocessing steps
    shpFileName = os.path.splitext (shpFile)[0]
    rastFile = shpFileName + "Rast.tif"
    arcpy.PointToRaster_conversion(shpFile, "Max_2015", rastFile, "MOST_FREQUENT", "", 0.05)

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.