arcpy.CopyFeatures_management 由于错误的命名约定而导致的错误
arcpy.CopyFeatures_management error due to bad naming convention
我有一个脚本可以每天下载一个 zip 文件并提取 shapefile。这工作正常,但 shapefile 始终采用 "polygons.yyyymmdd.shp"
格式
我在尝试将此文件复制到地理数据库时不断遇到错误。我猜是因为 shapefile 名称中有句点(不知道他们为什么使用这种命名结构)。
错误是"RuntimeError: Object: Error in executing tool"
shpList = arcpy.ListFeatureClasses()
print shpList
>>>[u'polygons.20150316.shp']
polyFc = "C:\data\work.gdb\" + "polyFc"
arcpy.CopyFeatures_management(shpList, polyFc)
地理处理工具将反对名称中带有额外句点的 shapefile(和 dbase 文件)。在使用 CopyFeatures 和其他工具之前需要重命名文件。
folder, shp_name = os.path.split(shp)
name = os.path.splitext(shp_name)[0]
for file_name in os.listdir(folder):
if file_name.startswith(name):
os.rename(os.path.join(folder, file_name),
os.path.join(folder, file_name.replace('.', '_', 1)))
# I renamed using the following:
for filename in os.listdir("."):
print filename
if filename.startswith("polygons"):
os.rename(filename, "a" + filename[9:])
# To import the shapefile into my geodb I converted the list to string first
shp = '\n'.join(shpList)
arcpy.FeatureClassToFeatureClass_conversion(shp, outWorkspace, "polyToday")
我有一个脚本可以每天下载一个 zip 文件并提取 shapefile。这工作正常,但 shapefile 始终采用 "polygons.yyyymmdd.shp"
格式我在尝试将此文件复制到地理数据库时不断遇到错误。我猜是因为 shapefile 名称中有句点(不知道他们为什么使用这种命名结构)。
错误是"RuntimeError: Object: Error in executing tool"
shpList = arcpy.ListFeatureClasses()
print shpList
>>>[u'polygons.20150316.shp']
polyFc = "C:\data\work.gdb\" + "polyFc"
arcpy.CopyFeatures_management(shpList, polyFc)
地理处理工具将反对名称中带有额外句点的 shapefile(和 dbase 文件)。在使用 CopyFeatures 和其他工具之前需要重命名文件。
folder, shp_name = os.path.split(shp)
name = os.path.splitext(shp_name)[0]
for file_name in os.listdir(folder):
if file_name.startswith(name):
os.rename(os.path.join(folder, file_name),
os.path.join(folder, file_name.replace('.', '_', 1)))
# I renamed using the following:
for filename in os.listdir("."):
print filename
if filename.startswith("polygons"):
os.rename(filename, "a" + filename[9:])
# To import the shapefile into my geodb I converted the list to string first
shp = '\n'.join(shpList)
arcpy.FeatureClassToFeatureClass_conversion(shp, outWorkspace, "polyToday")