# --------------------------------------------------------------------------- # RASTER2POLYGON.py # Created on: Wed Dec 01 2010 12:20:48 PM # (generated by ArcGIS/ModelBuilder) # Usage: RASTER2POLYGON <INPUT_RASTER> <Output_polygon_features> <Raster_Buffer_shp> # --------------------------------------------------------------------------- # 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... INPUT_RASTER = os.path.join(root + "\\" + filename_zero + ".png") gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features, "SIMPLIFY", "VALUE") Distance__value_or_field_ = "5 Meters" Raster_Buffer_shp = "SB_" + filename + ".shp" # Process: Buffer... gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE", "")
Solved! Go to Solution.
#--------------------- IMPORT -------------------------------------------------- import sys, string, os, arcgisscripting gp = arcgisscripting.create(9.3) # 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") #--------------------- INPUT --------------------------------------------------- gp.workspace = "D:/J040083" gp.CreateFileGDB ("D:/J040083", "ShapeFiles.gdb") folder = "D:/J040083/IMAGEFILES" #--------------------- SCRIPT -------------------------------------------------- gp.OverWriteOutput = 1 # overwrite existing files (1 = True, 0 = False) 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] extension = str.upper(filename_split[1]) try: first_2_letters = str.upper(filename_zero[0] + filename_zero[1]) except: first_2_letters = "XX" if first_2_letters == "LG" and extension == ".PNG": Output_polygon_features = "D:/J040083/ShapeFiles.gdb/" + "SH_" + filename_zero print (Output_polygon_features) # Process: Raster to Polygon... INPUT_RASTER = os.path.join(root + "/" + filename_zero + ".png") print (INPUT_RASTER) gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features) Distance__value_or_field_ = "5" Raster_Buffer_shp = "D:/J040083/ShapeFiles.gdb/" + "SB_" + filename_zero print (Raster_Buffer_shp) # Process: Buffer... gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE")