0

我正在尝试编写一个 python 脚本来将图像文件处理成 shapefile,然后用 5 米缓冲区来缓冲这些文件。我首先在 arcmap 的模型构建器中制作了脚本,但我试图为多个图像文件运行它,所有图像文件都以字母 LG 开头。我不断收到错误 00865,它指出输入栅格(图像文件)不存在!我已经检查了该文件夹一百万次,它确实存在!这是我的代码:

# 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", "")

有谁知道为什么它不起作用?谢谢你!

4

1 回答 1

0

我不知道你从哪里运行脚本,但是当你调用时gp.RasterToPolygon_conversion,你只给它文件,而不是完整路径。如果文件不在工作目录中,它将找不到它。尝试更换线路:

InRaster = filename_zero + ".png"

和:

InRaster = os.path.join(root, filename_zero + ".png")
于 2010-12-02T12:28:35.683 回答