Alice,
Guess no one is going to answer you. So here is my offering.
1) if you are on ArcGIS 9.3 (you're not on 9.2 are you?) you should create the Geoprocessor object with the 9.3 enhancements.
gp = arcgisscripting.create(9.3)
At ArcGIS 10 you can keep the (9.3) arcgisscripting syntax or shift to the more complete ArcPy Site Library.
2) You don't need to add the ArcToolbox code--those functions are included when you create the Geoprocessor in your Python script. And would cause problems if you were to add the script into a custom toolbox.
3) Working with the ShapeFiles.gdb File Geodatabase, you either need to have created it outside the script or create it when opening the script with:
gp.CreateFileGDB ("D:\\J04-0083", "ShapeFiles.gdb")
4) As scripted the result of the gp.RasterToPolygon is being output as ESRI Feature Classes within the File Geodatabase. But, you're putting your results into a file geodatabase "D:\\J04-0083\\ShapeFiles.gdb" and trying to name them .shp--that doesn't make them shape files. Rather, using the extension actually causes the gp script to throw an error. In your script, just drop the .shp and they'll be properly created as Polygon Feature Class in the geodatabase.
5) You went the other way with the Buffer_analysis. Output from that was dropping to the file system as Shape files in the D:\\J04-0083 folder. It would have been more consistent to keep both the geoprocessing polygon outputs together in the same format.
Again, I would drop the .shp extension, and direct the output into the file geodatabase--i.e., change the output path to D:\\J04-0083\\ShapeFiles.gdb.
Raster_Buffer_shp = "D:/J04-0083/ShapeFiles.gdb/" + "SB_" + filename_zero
6) Finally, the problem with scripting this way is that you will end up with output from each script run in the working directory. I think the reason you were getting the 99999 errors is probably because you had pieces left over from prior run that had name conflicts. You have to clear things out at each script restart, i.e. empty the working directory, and empty/delete the File Geodatabase.
Do that and you'll reach the more useful ExecuteErrors.
7) when you are done creating your buffers, work with them in the File Geodatabase. Or, you can export them to Shapefile if you need that format for some other application.
Here is your code cleaned up...I find forward slashes more readable than double backslashes, Python keeps it all straight. Also, if your PNG rasters have some projection details you may need world files for them to end up with usable results. I threw together some simple PNGs to test with, so your buffer value of "5 Meters" is set to "5" default pixels.
Code:
# ---------------------------------------------------------------------------
# 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(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")
# Script arguments...
gp.workspace = "D:/J04-0083"
gp.CreateFileGDB ("D:/J04-0083", "ShapeFiles.gdb")
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_zero
# Process: Raster to Polygon...
INPUT_RASTER = os.path.join(root + "/" + filename)
gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features)
Distance__value_or_field_ = "5"
Raster_Buffer_shp = "D:/J04-0083/ShapeFiles.gdb/" + "SB_" + filename_zero
# Process: Buffer...
gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE")
Post back if you are still stuck.
Stuart
Bookmarks