我浏览Stack Overflow下的以下帖子:Exploding overlapping polygons
我下载了帖子的初始作者发布的源代码并进行了调整以尝试使其正常工作,但我目前收到以下错误消息并且不确定如何解决它,请我建议我仍然学习编码,所以我缺乏基本理论。
错误讯息:文字
执行:OverlapReg E:\项目\ 2015年\ H111225_6 \ ArcHydro \ 27Jan15 \ 01SouthNorthAlign \ OverlappingWatershedsAnalysis.gdb \分水岭 HydroID2开始时间:2015年3月11日星期三14:58:32运行脚本 OverlapReg ...脚本失败OverlapReg ...
Traceback(最近一次调用最后一次):文件 " E:\的Python \大师\脚本\ OverlappingRegions \ OverlappingRegions.py&#34 ;, 第59行 countOverlaps(fc,idName)File" E:\ Python \ Masters \ Scripts \ OverlappingRegions \ OverlappingRegions.py", 第58行,在countOverlaps中 urows.updateRow(urow)文件" c:\ program files(x86)\ arcgis \ desktop10.2 \ arcpy \ arcpy \ arcobjects \ arcobjects.py",line 102,在updateRow中 return convertArcObjectToPythonObject(self._arc_object.UpdateRow(* gp_fixargs(args))) RuntimeError:ERROR 999999:执行函数时出错。该行包含 一个坏的价值。 [Watershed]该行包含错误的值。 [重叠]
执行失败(OverlapReg)。 2015年3月11日星期三14:58:35失败 (经过时间:2.45秒)
我尝试根据以下代码将ID分配给我的分水岭要素类,以便能够将我的分水岭要素类拆分为最少量的单独要素类,其中分水岭不会出现问题。 t彼此重叠,因为我需要将它们导出到AutoCAD图形中,其中单个图层中没有重叠的特征。
import os
import arcpy
from arcpy import GetParameterAsText
fc = GetParameterAsText(0)
idName = GetParameterAsText(1)
dirname = os.path.dirname(arcpy.Describe(fc).catalogPath)
desc = arcpy.Describe(dirname)
if hasattr(desc, "datasetType") and desc.datasetType=='FeatureDataset':
dirname = os.path.dirname(dirname)
arcpy.env.workspace = dirname
def countOverlaps(fc,idName):
intersect = arcpy.Intersect_analysis(fc,'intersect')
findID = arcpy.FindIdentical_management(intersect,"explFindID","Shape")
arcpy.MakeFeatureLayer_management(intersect,"intlyr")
arcpy.AddJoin_management("intlyr",arcpy.Describe("intlyr").OIDfieldName,findID,"IN_FID","KEEP_ALL")
segIDs = {}
featseqName = "explFindID.FEAT_SEQ"
idNewName = "intersect."+idName
for row in arcpy.SearchCursor("intlyr"):
idVal = row.getValue(idNewName)
featseqVal = row.getValue(featseqName)
segIDs[featseqVal] = []
for row in arcpy.SearchCursor("intlyr"):
idVal = row.getValue(idNewName)
featseqVal = row.getValue(featseqName)
segIDs[featseqVal].append(idVal)
segIDs2 = {}
for row in arcpy.SearchCursor("intlyr"):
idVal = row.getValue(idNewName)
segIDs2[idVal] = []
for x,y in segIDs.iteritems():
for segID in y:
segIDs2[segID].extend([k for k in y if k != segID])
for x,y in segIDs2.iteritems():
segIDs2[x] = list(set(y))
arcpy.RemoveJoin_management("intlyr",arcpy.Describe(findID).name)
if 'overlaps' not in [k.name for k in arcpy.ListFields(fc)]:
arcpy.AddField_management(fc,'overlaps',"TEXT")
if 'ovlpCount' not in [k.name for k in arcpy.ListFields(fc)]:
arcpy.AddField_management(fc,'ovlpCount',"SHORT")
urows = arcpy.UpdateCursor(fc)
for urow in urows:
idVal = urow.getValue(idName)
if segIDs2.get(idVal):
urow.overlaps = str(segIDs2[idVal]).strip('[]')
urow.ovlpCount = len(segIDs2[idVal])
urows.updateRow(urow)
countOverlaps(fc,idName)
def explodeOverlaps(fc,idName):
countOverlaps(fc,idName)
arcpy.AddField_management(fc,'expl',"SHORT")
urows = arcpy.UpdateCursor(fc,'"overlaps" IS NULL')
for urow in urows:
urow.expl = 1
urows.updateRow(urow)
i=1
lyr = arcpy.MakeFeatureLayer_management(fc)
while int(arcpy.GetCount_management(arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",'"expl" IS NULL')).getOutput(0)) > 0:
ovList=[]
urows = arcpy.UpdateCursor(fc,'"expl" IS NULL','','','ovlpCount D')
for urow in urows:
ovVal = urow.overlaps
idVal = urow.getValue(idName)
intList = ovVal.replace(' ','').split(',')
for x in intList:
intList[intList.index(x)] = int(x)
if idVal not in ovList:
urow.expl = i
urows.updateRow(urow)
ovList.extend(intList)
i+=1
explodeOverlaps(fc,idName)
如何解决以下问题的任何帮助都将真正受到赞赏。
答案 0 :(得分:1)
线索出现错误。
该行包含错误值[Watershed]
该行包含错误值[重叠]
这可能是因为尝试在字段重叠中插入一个值,但是由于字段属性的某些内容,例如长度为4,而您的值为"长字符串&#34 ;因此,它太大而无法插入。