使用Arcpy时发生“RuntimeError: ERROR 999998: Unexpected Error“错误

参考文章:http://t.csdn.cn/hvfFq

此问题为内存不足,先提供两种解决办法:

1.修改环境设置,将处理的范围缩小至需要区域,减少内存需要(推荐)

import arcpy

# Set the extent environment using a keyword
arcpy.env.extent = "MAXOF"

# Set the extent environment using the Extent class
arcpy.env.extent = arcpy.Extent(-107.0, 38.0, -104.0, 40.0)

# Set the extent environment using a space-delimited string
arcpy.env.extent = "-107.0 38.0 -104.0 40.0"

# Set the extent environment using a feature class
arcpy.env.extent = "C:/data/StudyArea_perim.shp"

# Set the extent environment using a raster
arcpy.env.extent = "C:/data/StudyArea.tif"

2.分段运行,并添加内存清理代码

import arcpy
from arcpy import env
from arcpy.sa import *

env.workspace = "E:/WorkSpace/Python/data/"
arcpy.ClearWorkspaceCache_management()  # 在指明工作空间后使用
arcpy.Delete_management("in_memory")