如何使用ArcGIS/Python生成输入参数?

如何使用ArcGIS/Python生成输入参数?,python,gis,arcgis,arcpy,Python,Gis,Arcgis,Arcpy,我是Python的新手。我正在尝试使用arcpy.GetParameterAsText函数将“源文件夹”和“地理数据库”作为ArcGIS工具箱中的输入参数 我真的不确定把这两个arcpy.GetParameterAsText函数放在哪里。是否要将工作区设置为它?如果我这样做,我不知道如何创建没有路径的GDB文件 # Set the workspace arcpy.env.workspace = "C:\\Users\\x\\Desktop\\Python_Scripting\\4\\Lesson

我是Python的新手。我正在尝试使用
arcpy.GetParameterAsText
函数将“源文件夹”和“地理数据库”作为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"

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)