Python 2.7 如何在文件GDB、ArcGIS中设置工作空间

Python 2.7 如何在文件GDB、ArcGIS中设置工作空间,python-2.7,gis,Python 2.7,Gis,我正在创建一个脚本,创建一个新的空文件GDB和FeatureDataset,但我不知道如何设置脚本的所有输出将自动保存在文件GDB或FeatureDataset中。现在我正在使用一个界面,以便用户必须为所有分析指定输出,但由于我有很多输出,我希望减少界面中的输出数量(例如点、线、多边形等)。 例如: import arcpy GDB_Location = arcpy.GetParameterAsText(0) GDB_name = arcpy.GetParameterAsText(1) GDB_

我正在创建一个脚本,创建一个新的空文件GDB和FeatureDataset,但我不知道如何设置脚本的所有输出将自动保存在文件GDB或FeatureDataset中。现在我正在使用一个界面,以便用户必须为所有分析指定输出,但由于我有很多输出,我希望减少界面中的输出数量(例如点、线、多边形等)。 例如:

import arcpy
GDB_Location = arcpy.GetParameterAsText(0)
GDB_name = arcpy.GetParameterAsText(1)
GDB_file = arcpy.CreateFileGDB_management(GDB_Location, GDB_name)
out_dataset_path = GDB_file
out_dataset_name = arcpy.GetParameterAsText(2)
feature_dataset = arcpy.CreateFeatureDataset_management(out_dataset_path,out_dataset_name)
point= arcpy.GetParameterAsText(3)
line = arcpy.GetParameterAsText(4)
poly = arcpy.GetParameterAsText(5)

..

您希望在代码中包含两件事:

  • 创建地理数据库的步骤
  • 可在后续步骤中用于引用该地理数据库的变量
  • 创建地理数据库(GDB)或要素数据集的ArcPy函数不会同时生成变量。将其视为两个独立的步骤,然后您将能够为该输出工作区设置一个变量

    import arcpy
    import os
    
    GDB_Location = arcpy.GetParameterAsText(0)
    GDB_name = arcpy.GetParameterAsText(1)
    # function to create the GDB
    arcpy.CreateFileGDB_management(GDB_Location, GDB_name)
    # variable to refer to the GDB
    gdb = os.path.join(GDB_Location, GDB_name)
    
    dataset_name = arcpy.GetParameterAsText(2)
    # function to create the dataset
    arcpy.CreateFeatureDataset_management(gdb, dataset_name)
    # variable to refer to the dataset
    dataset = os.path.join(gdb, dataset_name)
    
    如果您想减少用户需要填写的输入参数的数量,可以自己在代码中生成名称——这一决定实际上取决于最终用户想要什么

    “中间”的替代方案是建议用户可能想要使用什么。这样,他们可以选择简单的方式(使用默认值),或者做更多的工作来定制输出功能名称

    # EITHER have user provide the output feature class name
    pointName = arcpy.GetParameterAsText(3)
    # OR name the points yourself
    pointName = "output_point"
    
    # and then concatenate that together with the geodatabase and feature dataset
    pointFeature = os.path.join(gdb, dataset, pointName)
    # then use variable "pointFeature" in subsequent functions to create that feature