如何在ArcGIS / Python中将要素类复制到新的地理数据库中?

时间:2016-03-07 23:14:52

标签: python python-2.7 arcgis arcpy

我正在尝试将要素类从文件夹复制到新的地理数据库中,但这些文件都不会复制到新的地理数据库中。他们为什么不复制?

import arcpy
from arcpy import env
env.workspace="C:\\Users\\welchk\\Desktop\\HW6_data\\data\\"
env.overwriteOutput=True

#creating the gdb
arcpy.CreateFileGDB_management("C:\\Users\\welchk\\Desktop\\HW6_data\\data\\", "t_6.gdb")

#creates a list using ListFeatureClasses function
fclist=arcpy.ListFeatureClasses("*", "polygon")

#uses CopyFeatures_management function to copy feature classes in the list to the data folder. 
for fc in fclist:
#Uses the describe function so below you can tell the basename
    fcdesc=arcpy.Describe(fc)
#copies the features using a function that saves the new feature class with the basename.
arcpy.CopyFeatures_management(fc, "C:\\Users\\welchk\\Desktop\\HW6_data\\data\\t_6.gdb"+fcdesc.basename)

1 个答案:

答案 0 :(得分:3)

"...t_6.gdb" + fcdesc.basename

您的输出文件路径缺少分隔符。

例如,如果fcdesc.basename = counties,则上述代码尝试创建...t_6.gdbcounties(并且它实际上会创建shapefile)而不是...t_6.gdb\\counties(地理数据库中的要素类) )。

包括结束分隔符,它按预期运行:

"C:\\[directories]\\t_6.gdb\\" + fcdesc.basename