Python 2.7 如何在文件GDB、ArcGIS中设置工作空间
我正在创建一个脚本,创建一个新的空文件GDB和FeatureDataset,但我不知道如何设置脚本的所有输出将自动保存在文件GDB或FeatureDataset中。现在我正在使用一个界面,以便用户必须为所有分析指定输出,但由于我有很多输出,我希望减少界面中的输出数量(例如点、线、多边形等)。 例如: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_
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)
..您希望在代码中包含两件事:
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