操作方法

操作方法:打印 ArcSDE 地理数据库的要素类列表

Last Published: August 7, 2020

摘要

提供的说明描述了如何打印 ArcSDE 地理数据库的要素类列表。

过程

运行以下 Python 脚本将生成所选 SDE 地理数据库中所有要素类的列表。

  1. 打开 ArcMap。

  2. 单击 Python 窗口按钮。

    [O-Image] PythonWindow2
 
import arcpy
from arcpy import env 
import os

# Establish connection for workspace 

env.workspace = r"Database Connections\Child Database"

#call ListFeatureClass function
fcList = arcpy.ListFeatureClasses()

# Print the name of the current fc:
for fc in fcList:
print fc
  1. 编辑以下脚本。 选择 SDE 连接文件的名称或者地理数据库连接的位置。 使用 ## 注释掉未使用的部分。
可以通过以下两种方法将数据库工作空间输入到 Python 脚本中:
  • 提供地理数据库的数据库连接路径的位置。 从 ArcCatalog 窗口复制路径。
[O-Image] Location777
  • 提供地理数据库的 SDE 连接路径的文件名。 右键单击所选数据连接,单击属性,然后在常规选项卡上,从名称字段中提取路径。 从 ArcCatalog 窗口复制路径。
[O-Image] DatabaseProperties
  1. 将以上复制的路径粘贴到 Python 脚本中。
[O-Image] CopynPaste
  1. 将以上整个脚本粘贴到 ArcMap 的 Python 窗口中,然后按 Enter 键。 随即显示 ArcSDE 要素类列表。
  2. 要将 ArcSDE 要素类打印至文件,请参阅以下代码:
import arcpy
from arcpy import env 
import os

# Set the workspace for the ListFeatureClass function 
env.workspace = r"Database Connections\Child Database 1017857.sde"
# Use the ListFeatureClasses function to return a list of all fc's in the sde gdb: 
fcList = arcpy.ListFeatureClasses() 

# Write the name of the current fc in text file:
txtFile = open(r"C:\data\FeatureClassList.txt","w")
for fc in fcList:
print fc

# Write messages to a Text File
txtFile.write(fc)
txtFile.write (os.linesep)

#close text file
txtFile.close()

print "done"
:
要将此脚本转换为地理处理服务,需要替换环境工作空间参数,如下所示:
env.Workspace = arcpy.GetParameterAsText(0)

文章 ID:000011504

从 ArcGIS 专家处获得帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项

发现关于本主题的更多内容