I am trying to write a python script to process image files into shapefiles and then to buffer these files with a 5 meter buffer. I first made the script in model builder in arcmap but I am trying to run it for multiple image files, all beginning with the letters LG. I keep getting the error 00865, which states that the input raster (image file) does not exist!! I have checked the folder a million times and it definitely does exist! Here is my code:
# Import system modules
import sys, string, os, arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
# Script arguments...
folder = "D:\\J04-0083\\IMAGEFILES"
for root, dirs, filenames in os.walk(folder): # returms root, dirs, and files
for filename in filenames:
filename_split = os.path.splitext(filename) # filename and extensionname (extension in [1])
filename_zero = filename_split[0]
try:
first_2_letters = filename_zero[0] + filename_zero[1]
except:
first_2_letters = "XX"
if first_2_letters == "LG":
Output_polygon_features = "D:\\J04-0083\\ShapeFiles.gdb\\" + "SH_" + filename + ".shp"
# Process: Raster to Polygon...
InRaster = filename_zero + ".png"
gp.RasterToPolygon_conversion(InRaster, Output_polygon_features, "SIMPLIFY", "VALUE") # FILL IN THE CORRECT VALUES!
Distance__value_or_field_ = "5 Meters"
Raster_Buffer_shp = "D:\\J04-0083\\ShapeFiles.gdb\\" + "SB_" + filename + ".shp"
# Process: Buffer...
gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE", "")
Does anyone have any idea why it doesn't work? thank you!
I don't know where you're running the script from, but when you call gp.RasterToPolygon_conversion
, you're only giving it the file name, not the full path. If the file's not in the working directory, it won't find it. Try replacing the line:
InRaster = filename_zero + ".png"
With:
InRaster = os.path.join(root, filename_zero + ".png")