管理功能\copy arcu错误的命名约定导致错误

2024-10-02 10:27:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个脚本,每天下载一个zip文件并提取shapefile。这很好,但shapefile的格式始终为“多边形.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)

Tags: 文件脚本名称数据库格式zip多边形地理
2条回答
# 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")

地理处理工具将反对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)))

相关问题 更多 >

    热门问题