如何在ArcGIS/Python中创建输入参数?

2024-10-01 07:28:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python是全新的。我试图使用arcpy.GetParameterAsText函数将“source folder”和“geodatabase”作为ArcGIS工具箱中的输入参数。在

我真的不知道把这两个arcpy.GetParameterAsText函数放在哪里。是否要将工作区设置为它?如果我这样做,我不知道如何创建前面没有路径的GDB文件。在

# Set the workspace
arcpy.env.workspace = "C:\\Users\\x\\Desktop\\Python_Scripting\\4\\Lesson4_Data\\Lesson4_Data"

#Create the GDB
arcpy.CreateFileGDB_management("C:\\Users\\x\\Desktop\\Python_Scripting\\4\\Lesson4_Data\\Lesson4_Data","lesson4a.gdb")

# Set the feature class variables
fclist = arcpy.ListFeatureClasses("","polygon")
fctotal = arcpy.ListFeatureClasses()

# Start the loop on all feature classes
for fc in fclist:
    fcdesc = arcpy.Describe(fc)
    print fcdesc.basename + " is currently importing into the lesson4a.gdb."
    arcpy.CopyFeatures_management (fc, "C:\\Users\\x\\Desktop\\Python_Scripting\\4\\Lesson4_Data\\Lesson4_Data\\lesson4a.gdb\\" + fcdesc.basename)
    print fcdesc.basename + " is done importing into the lesson4a.gdb.\n"

Tags: the函数datausersfcdesktoparcpyscripting
1条回答
网友
1楼 · 发布于 2024-10-01 07:28:02

arcpy.GetParameterAsText(#)函数将从ArcGIS工具读取输入参数。在

在编写脚本和调试期间,最简单的方法是硬编码函数的输入变量,以验证函数是否正常工作。一旦工具(本质上)是您想要的方式,在ArcMap中创建工具箱和脚本工具。在

要接受来自工具执行对话框的输入参数,您需要在创建脚本工具时创建它们(并更改代码以接受GetParameterAsText输入)。最好的演练是ArcGIS资源中心。在

在Python脚本中,我通常首先读取输入参数,这样,它们就可以作为脚本其余部分的变量使用。索引值指示哪个参数是哪个。在

# Input parameters
sourceFolder = arcpy.GetParameterAsText(0)        # first input parameter of script tool
geodatabaseName = arcpy.GetParameterAsText(1)     # second input parameter

# Set the workspace
arcpy.env.workspace = sourceFolder

#Create the GDB
arcpy.CreateFileGDB_management(sourceFolder, geodatabaseName)

相关问题 更多 >