【问题标题】:How do I make input parameters with ArcGIS/Python?如何使用 ArcGIS/Python 制作输入参数?
【发布时间】:2016-04-15 03:26:42
【问题描述】:

我是 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"

【问题讨论】:

    标签: python gis arcgis arcpy


    【解决方案1】:

    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)
    

    【讨论】:

      猜你喜欢
      • 2017-11-06
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      • 2019-10-11
      相关资源
      最近更新 更多