# 导入ArcPy模块 import arcpy # 设置工作空间 arcpy.env.workspace = r"C:\data\example.gdb" # 要素类列表 fc_list = arcpy.ListFeatureClasses() # 指定输出目录 out_folder = r"C:\data\output" # 循环要素类列表并导出 for fc in fc_list: # 导出Shapefile arcpy.FeatureClassToShapefile_conversion(fc, out_folder) # 导出File Geodatabase out_name = fc.split(".")[0] + ".gdb" arcpy.Copy_management(fc, out_folder + "\\" + out_name)运行错误:Traceback (most recent call last): File "D:\多对一空间连接\批量导出数据.py", line 13, in <module> NameError: name 'fc_list' is not defined 执行(批量导数据)失败。请改正代码
时间: 2023-12-14 13:38:39 浏览: 112
arcpy 批量获取gdb下图层的字段别名及属性域
在第7行之前,需要先定义fc_list变量,例如:
```
fc_list = []
```
然后在第7行之后,将获取的要素类添加到fc_list中,例如:
```
for dirpath, dirnames, filenames in arcpy.da.Walk(arcpy.env.workspace, datatype="FeatureClass"):
for filename in filenames:
fc_list.append(os.path.join(dirpath, filename))
```
完整代码如下:
```
import arcpy
import os
arcpy.env.workspace = r"C:\data\example.gdb"
fc_list = []
for dirpath, dirnames, filenames in arcpy.da.Walk(arcpy.env.workspace, datatype="FeatureClass"):
for filename in filenames:
fc_list.append(os.path.join(dirpath, filename))
out_folder = r"C:\data\output"
for fc in fc_list:
arcpy.FeatureClassToShapefile_conversion(fc, out_folder)
out_name = fc.split(".")[0] + ".gdb"
arcpy.Copy_management(fc, out_folder + "\\" + out_name)
```
阅读全文