def searchALL(targetpath): """获取所有图斑中的exp_bsm,fzh和bhlx,如果图斑图层不存在fzh和bhlx,则创建字段""" datas = [] fzhlist = [] targetValueDict = {} searchFields = ["exp_tbwym", 'fzh'] tempFields = ["exp_tbwym", 'fzh'] arcpyDeal.ensureFields(targetpath, searchFields) arcpyDeal.createTempDatas(searchFields, tempFields, targetpath, datas) for data in datas: fzh = dealNone.dealNoneAndBlank(data['fzh']) if fzh != "": if int(fzh) not in fzhlist: fzhlist.append(int(fzh)) targetValueDict[data['exp_tbwym']] = {"fzh": fzh} fzhlist.sort() return fzhlist, targetValueDict
def searchFzh(targetpath): """获取所有图斑中的unionfzh,如果图斑图层不存在unionfzhfzh,则创建字段""" unionfzhlist = [] targetValueDict = {} datas = [] searchFields = ["TSTYBM", "unionfzh"] tempFields = ["TSTYBM","unionfzh"] arcpyDeal.ensureFields(targetpath,searchFields) sql_clause = (None,"ORDER BY unionfzh") arcpyDeal.createTempDatas(searchFields,tempFields,targetpath,datas,sql_clause = sql_clause) for data in datas: unionfzh = dealNone.dealNoneAndBlank(data['unionfzh']) if unionfzh != "": unionfzhlist.append(int(unionfzh)) targetValueDict[data['TSTYBM']] = {"unionfzh":unionfzh} unionfzhlist.sort() return unionfzhlist,targetValueDict
def updateDatas(targetpath): """根据OLDTAG和ZZJZTB更新图斑变化类型,添加图斑预编号(tbybh)""" #根据查询的数据更新数据 searchFields = [ 'OLDTAG', 'ZZJZTB', "exp_tblx", "exp_tbybh", "exp_tbwym", "TSTYBM" ] arcpyDeal.ensureFields(targetpath, searchFields) number = 0 with arcpy.da.UpdateCursor(targetpath, searchFields) as UpdateCursor: for updaterow in UpdateCursor: number += 1 oldTag = updaterow[0] zzjztb = updaterow[1] exp_tblx = judgeTBLX(oldTag, zzjztb) exp_tbybh = "00000000"[0:8 - len(str(number))] + str(number) updaterow[2] = exp_tblx updaterow[3] = exp_tbybh updaterow[4] = updaterow[5] UpdateCursor.updateRow(updaterow) arcpy.SetProgressorPosition()
def dissolveGetFzh(xzkPath, dissolvepath, outputxzkpath): """融合得到新分组号""" arcpy.MakeFeatureLayer_management(xzkPath, "xzkPath") arcpy.SelectLayerByAttribute_management("xzkPath", 'NEW_SELECTION', "shpvary = 'Y'") arcpy.Dissolve_management("xzkPath", dissolvepath, 'shpvary', '', 'SINGLE_PART', 'UNSPLIT_LINES') arcpyDeal.ensureFields(dissolvepath, ['relfzh'], "LONG") tmpcur = arcpy.da.UpdateCursor(dissolvepath, ['relfzh']) num = 5000000 for row in tmpcur: row[0] = num num = num + 1 tmpcur.updateRow(row) arcpy.SpatialJoin_analysis(xzkPath, dissolvepath, outputxzkpath, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_ALL", match_option="WITHIN")
def createRelation(relationList, enviroment, relationpath, dellinktbspath): """融合照片点输出照片""" arcpy.SetProgressor('step', '6_设置LINKTBS值', 0, len(relationList), 1) arcpy.CreateTable_management(enviroment, relationpath) newFields = ["oldfield", "newfields"] arcpyDeal.ensureFields(relationpath, newFields) insertcur = arcpy.da.InsertCursor(relationpath, newFields) arcpy.MakeFeatureLayer_management(dellinktbspath, "dellinktbspath") for relation in relationList: arcpy.SelectLayerByAttribute_management("dellinktbspath", where_clause=" TSTYBM = '%s'" % (relation[0])) count = int(arcpy.GetCount_management("dellinktbspath").getOutput(0)) if count > 0: insertcur.insertRow(relation) arcpy.SetProgressorPosition()
def markError(xzkpath, targetValueList): """标记错误图斑""" searchFields = ["TSTYBM", "error"] arcpyDeal.deleteFields(xzkpath, ["error"]) arcpyDeal.ensureFields(xzkpath, searchFields) with arcpy.da.UpdateCursor(xzkpath, searchFields) as cur: for row in cur: arcpy.SetProgressorPosition() TSTYBM = row[0] if TSTYBM in targetValueList: row[1] = '0' else: row[1] = "1" cur.updateRow(row)
def searchFzh(targetpath): """获取所有图斑中的fzh和bhlx,如果图斑图层不存在fzh和bhlx,则创建字段""" fzhlist = [] targetValueDict = {} datas = [] searchFields = ["TSTYBM", "bhlx", "fzh"] tempFields = ["TSTYBM", "bhlx", "fzh"] arcpyDeal.ensureFields(targetpath, searchFields) sql_clause = (None, "ORDER BY fzh") arcpyDeal.createTempDatas(searchFields, tempFields, targetpath, datas, sql_clause=sql_clause) for data in datas: fzh = dealNone.dealNoneAndBlank(data['fzh']) bhlx = dealNone.dealNoneAndBlank(data['bhlx']) if fzh != "": fzhlist.append(int(fzh)) targetValueDict[data['TSTYBM']] = {"bhlx": bhlx, "fzh": fzh} fzhlist.sort() return fzhlist, targetValueDict
def UpdateTarget(targetpath, matchedDataDict): """更新还原初始库属性""" bsmDifference = [] zldwdmDifference = [] sjdlbmDifference = [] tstybmDifference = [] fields = ["TSTYBM", "exp_bsm", "exp_sjdlbm", "exp_zldwdm"] arcpyDeal.ensureFields(targetpath, fields) cursor = arcpy.da.UpdateCursor(targetpath, fields, where_clause=" TSTYBM is not null", sql_clause=(None, 'ORDER BY TSTYBM')) for row in cursor: arcpy.SetProgressorPosition() tstybm = row[0] if tstybm not in matchedDataDict: tstybmDifference.append(tstybm) continue if matchedDataDict[tstybm]["bsm"] != matchedDataDict[tstybm]["bsm_1"]: bsmDifference.append(tstybm) if matchedDataDict[tstybm]["zldwdm"] != matchedDataDict[tstybm][ "zldwdm_1"]: zldwdmDifference.append(tstybm) if matchedDataDict[tstybm]["sjdlbm"] != matchedDataDict[tstybm][ "sjdlbm_1"]: sjdlbmDifference.append(tstybm) row[1] = matchedDataDict[tstybm]["bsm"] row[2] = matchedDataDict[tstybm]["sjdlbm"] row[3] = matchedDataDict[tstybm]["zldwdm"] cursor.updateRow(row) arcpy.AddMessage("2_共有%s个图斑bsm不同" % (len(bsmDifference))) arcpy.AddMessage("2_共有%s个图斑zldwdm不同" % (len(zldwdmDifference))) arcpy.AddMessage("2_共有%s个图斑sjdlbm不同" % (len(sjdlbmDifference))) arcpy.AddMessage("2_共有%s个图斑无初始库图斑" % (len(tstybmDifference))) arcpy.AddMessage("2_" + json.dumps(bsmDifference)) arcpy.AddMessage("2_" + json.dumps(zldwdmDifference)) arcpy.AddMessage("2_" + json.dumps(sjdlbmDifference)) arcpy.AddMessage("2_" + json.dumps(tstybmDifference))
def collect2(targetpath): """收集保留和需要删除的图斑""" searchFields = ["TSTYBM", "exp_bsm", "intersecrteddeal", "JZSJ"] sql_clause = (None, " ORDER BY exp_bsm,JZSJ DESC") arcpyDeal.deleteFields(targetpath, ["intersecrteddeal"]) arcpyDeal.ensureFields(targetpath, searchFields) searchFields.append("SHAPE@WKT") targetValueDict = {} datas = {} lastbsm = "" for row in arcpy.da.SearchCursor(targetpath, searchFields, sql_clause=sql_clause): data = dict(zip(searchFields, row)) data["intersecrteddeal"] = dealNone.dealNoneAndBlank( data["intersecrteddeal"]) if lastbsm == "": lastbsm = data["exp_bsm"] elif lastbsm != data["exp_bsm"]: compary(lastbsm, datas[lastbsm]) lastbsm = data["exp_bsm"] if data["exp_bsm"] not in datas: datas[data["exp_bsm"]] = [data] else: datas[data["exp_bsm"]].append(data) arcpy.SetProgressorPosition() compary(lastbsm, datas[lastbsm]) for key in datas: for data in datas[key]: targetValueDict[data["TSTYBM"]] = data["intersecrteddeal"] return targetValueDict
def createFianllyAttributesFields(targetpath): """创建最终确定的地类编码,耕地种植属性代码,耕地类型,图斑细化代码""" fields = [ "exp_tbbh", "exp_wjzlx", "exp_czcsxm", "bhlx", "exp_dlbm", "exp_dlmc", "exp_gdzzsxdm", "exp_gdzzsxmc", "exp_gdlx", "exp_tbxhdm", "exp_tbxhmc", "DLBM_1", "GDZZSXMC_1", "GDLX_1", "TBXHMC_1" ] arcpyDeal.ensureFields(targetpath, fields)
def collectRepetitive(xzkpath): """收集需要删除的图斑""" searchFields = ["TSTYBM","cskbsm","repetitive"] sql_clause = (None," ORDER BY cskbsm,SHAPE_AREA DESC") arcpyDeal.deleteFields(xzkpath,["repetitive"]) arcpyDeal.ensureFields(xzkpath,searchFields) searchFields.append("SHAPE@WKT") searchFields.append("SHAPE_AREA") targetValueDict = {} datas = {} lastbsm = "" for row in arcpy.da.SearchCursor(xzkpath,searchFields,sql_clause= sql_clause): arcpy.SetProgressorPosition() data = dict(zip(searchFields,row)) data["repetitive"] = dealNone.dealNoneAndBlank(data["repetitive"]) if lastbsm == "": lastbsm = data["cskbsm"] elif lastbsm != data["cskbsm"]: compary(lastbsm,datas[lastbsm]) lastbsm = data["cskbsm"] if data["cskbsm"] not in datas: datas[data["cskbsm"]] = [data] else: datas[data["cskbsm"]].append(data) compary(lastbsm,datas[lastbsm]) for key in datas: for data in datas[key]: targetValueDict[data["TSTYBM"]] = data["repetitive"] return targetValueDict
def createWidth(tempname): """创建平均宽度,用于处理狭长图斑""" arcpyDeal.ensureFields(tempname, ["width"], type="Double") expression = "getClass(float(!SHAPE.area!),float(!SHAPE.length!))" codeblock = """def getClass(area,length): return area/length """ arcpy.CalculateField_management(tempname, "width", expression, "PYTHON_9.3", codeblock)
def getCskArea(cskpath): """计算初始库面积""" arcpyDeal.ensureFields(cskpath, ["cskmianji"], type="DOUBLE") cskcur = arcpy.da.UpdateCursor(cskpath, ['cskmianji', 'SHAPE@AREA']) for row in cskcur: row[0] = row[1] cskcur.updateRow(row)
def getRelation(outputxzkpath1, outputxzkpath2, enviroment, relationpath): """插入新旧图属统一编码关系""" relationList = [] count = int(arcpy.GetCount_management(outputxzkpath1).getOutput(0)) + int( arcpy.GetCount_management(outputxzkpath2).getOutput(0)) arcpy.SetProgressor('step', '7_获取照片点融合', 0, count, 1) with arcpy.da.SearchCursor(outputxzkpath1, ["TSTYBM", "tstybmlist"]) as cur: for row in cur: if len(row[1]) > 36: tstybmlist = row[1].split(",") for oldtstybm in tstybmlist: relationList.append([oldtstybm, row[0]]) arcpy.SetProgressorPosition() with arcpy.da.SearchCursor(outputxzkpath2, ["TSTYBM", "tstybmlist"]) as cur: for row in cur: if len(row[1]) > 36: tstybmlist = row[1].split(",") for oldtstybm in tstybmlist: relationList.append([oldtstybm, row[0]]) arcpy.SetProgressorPosition() arcpy.CreateTable_management(enviroment, relationpath) newFields = ["oldfield", "newfields"] arcpyDeal.ensureFields(relationpath, newFields) insertcur = arcpy.da.InsertCursor(relationpath, newFields) for relation in relationList: insertcur.insertRow(relation) arcpy.SetProgressorPosition()
def judge(outputxzkpath): """判断变化类型""" arcpy.SetProgressor( 'step', "8_判断变化类型", 0, int(arcpy.GetCount_management(outputxzkpath).getOutput(0)), 1) arcpyDeal.ensureFields(outputxzkpath, ['shuvary', 'shpvary']) xzkcur = arcpy.da.UpdateCursor(outputxzkpath, ['cskmianji', 'SHAPE@AREA', 'shpvary']) for row in xzkcur: if abs(row[0] - row[1]) < 0.1: row[2] = 'N' else: row[2] = 'Y' xzkcur.updateRow(row) searchFields = [ 'shuvary', 'dlbm', 'cskdlbm', "WJZLX", 'GDLX', 'TBXHDM', 'GDZZSXDM' ] xzkcur = arcpy.da.UpdateCursor(outputxzkpath, searchFields) for row in xzkcur: data = dict(zip(searchFields, row)) if data["dlbm"] == data["cskdlbm"] and data['WJZLX'] == '' and data[ 'GDLX'] == '' and data['TBXHDM'] == '' and data[ 'GDZZSXDM'] == '': row[0] = 'N' else: row[0] = 'Y' xzkcur.updateRow(row)
def markRepetitive(xzkpath,targetValueDict): """标记需要删除的图斑""" searchFields = ["TSTYBM","repetitive"] arcpyDeal.ensureFields(xzkpath,searchFields) with arcpy.da.UpdateCursor(xzkpath,searchFields) as cur: for row in cur: TSTYBM = row[0] row[1] = targetValueDict[TSTYBM] cur.updateRow(row) arcpy.SetProgressorPosition()
def mark2(targetpath, targetValueDict, targetValueList): """标记保留和需要删除的图斑""" searchFields = ["TSTYBM", "intersecrteddeal"] arcpyDeal.ensureFields(targetpath, searchFields) cur = arcpy.da.UpdateCursor(targetpath, searchFields) for row in cur: TSTYBM = row[0] row[1] = targetValueDict[TSTYBM] cur.updateRow(row) arcpy.SetProgressorPosition()
def searchLinkTBS(targetpath): """查找拥有LINKTBS的图斑,并返回数据列表""" where_clause = "LINKTBS <> '' and LINKTBS is not null " tempTargerPah = "tempLinkTBS" datas = [] searchFields = ["TSTYBM",'LINKTBS','unionfzh'] tempFields = ["TSTYBM",'linktbs','unionfzh'] arcpyDeal.ensureFields(targetpath,searchFields) arcpyDeal.createTempDatas(searchFields,tempFields,targetpath,datas,where_clause = where_clause) arcpy.Delete_management(tempTargerPah) arcpy.AddMessage("7_共有%s个图斑存在LINKTBS"%(len(datas))) return datas
def judge(xzkPath): """判断变化类型""" xzknum = int(arcpy.GetCount_management(xzkPath).getOutput(0)) arcpyDeal.ensureFields(xzkPath, ['shuvary', 'shpvary']) xzkcur = arcpy.da.UpdateCursor(xzkPath, ['cskmianji', 'SHAPE@AREA', 'shpvary']) for row in xzkcur: if abs(float(row[0].decode("utf-8")) - row[1]) < 0.1: row[2] = 'N' else: row[2] = 'Y' xzkcur.updateRow(row) searchFields = [ 'shuvary', 'dlbm', 'cskdlbm', "WJZLX", 'GDLX', 'TBXHDM', 'GDZZSXDM' ] xzkcur = arcpy.da.UpdateCursor(xzkPath, searchFields) for row in xzkcur: data = dict(zip(searchFields, row)) if data["dlbm"] == data["cskdlbm"] and data['WJZLX'] != '' and data[ 'GDLX'] != '' and data['TBXHDM'] != '' and data[ 'GDZZSXDM'] != '': row[0] = 'N' else: row[0] = 'Y' xzkcur.updateRow(row)
def updateTarget(targetpath, targetValueDict): """更新数据""" #根据查询的数据更新数据 searchFields = [ "unionfzh", "exp_bsm", "exp_tbybh", "exp_tbbh", "exp_zldwdm", "exp_dlbm", "exp_dlmc", "exp_gdlx", "exp_tbxhdm", "exp_tbxhmc", "exp_gdzzsxdm", "exp_gdzzsxmc", "exp_czcsxm", "exp_tblx", "exp_tbwym", "bhlx", "exp_wjzlx", "fzh" ] arcpyDeal.ensureFields(targetpath, searchFields) UpdateCursor = arcpy.da.UpdateCursor(targetpath, searchFields) for updaterow in UpdateCursor: unionfzh = updaterow[0] updaterow[1] = targetValueDict[unionfzh]['exp_bsm'] updaterow[2] = targetValueDict[unionfzh]['exp_tbybh'] updaterow[3] = targetValueDict[unionfzh]['exp_tbbh'] updaterow[4] = targetValueDict[unionfzh]['exp_zldwdm'] updaterow[5] = targetValueDict[unionfzh]['exp_dlbm'] updaterow[6] = targetValueDict[unionfzh]['exp_dlmc'] updaterow[7] = targetValueDict[unionfzh]['exp_gdlx'] updaterow[8] = targetValueDict[unionfzh]['exp_tbxhdm'] updaterow[9] = targetValueDict[unionfzh]['exp_tbxhmc'] updaterow[10] = targetValueDict[unionfzh]['exp_gdzzsxdm'] updaterow[11] = targetValueDict[unionfzh]['exp_gdzzsxmc'] updaterow[12] = targetValueDict[unionfzh]['exp_czcsxm'] updaterow[13] = targetValueDict[unionfzh]['exp_tblx'] updaterow[14] = targetValueDict[unionfzh]['exp_tbwym'] updaterow[15] = targetValueDict[unionfzh]['bhlx'] updaterow[16] = targetValueDict[unionfzh]['exp_wjzlx'] updaterow[17] = targetValueDict[unionfzh]['fzh'] UpdateCursor.updateRow(updaterow) arcpy.SetProgressorPosition()
def searchALL(targetpath): """获取所有图斑中的exp_bsm,fzh和bhlx,如果图斑图层不存在fzh和bhlx,则创建字段""" sql_clause = (None, "ORDER BY exp_bsm") datas = [] fzhlist = [] targetValueDict = {} searchFields = ["TSTYBM", "exp_bsm", 'bhlx', 'fzh'] arcpyDeal.ensureFields(targetpath, searchFields) cursor = arcpy.da.SearchCursor(targetpath, searchFields, sql_clause=sql_clause) for row in cursor: data = dict(zip(searchFields, row)) datas.append(data) fzh = dealNone.dealNoneAndBlank(data['fzh']) bhlx = dealNone.dealNoneAndBlank(data['bhlx']) if fzh != "": if int(fzh) not in fzhlist: fzhlist.append(int(fzh)) targetValueDict[data['TSTYBM']] = {"bhlx": bhlx, "fzh": fzh} fzhlist.sort() return datas, fzhlist, targetValueDict
def mergePhoto(photopath, tbwymRelation): """合并照片""" searchFields = ["TSTYBM", "exp_tstybm"] arcpyDeal.ensureFields(photopath, searchFields) with arcpy.da.UpdateCursor(photopath, searchFields) as UpdateCursor: for updaterow in UpdateCursor: updaterow[1] = updaterow[0] UpdateCursor.updateRow(updaterow) arcpy.SetProgressorPosition() #根据查询的数据更新数据 searchFields = ["exp_tstybm"] with arcpy.da.UpdateCursor(photopath, searchFields) as UpdateCursor: for updaterow in UpdateCursor: exp_tstybm = updaterow[0] if exp_tstybm in tbwymRelation: updaterow[0] = tbwymRelation[exp_tstybm] UpdateCursor.updateRow(updaterow) else: continue arcpy.SetProgressorPosition()
def start(targetpath): arcpy.AddMessage("8_重新生成union字段") arcpyDeal.deleteFields(targetpath, ["unionfzh"]) arcpyDeal.ensureFields(targetpath, ["unionfzh"]) arcpy.AddMessage("8_收集原有分组号") fzhlist, targetValueDict = searchALL(targetpath) arcpy.AddMessage("8_收集融合分组号") unionfzhlist = [] result = arcpy.GetCount_management(targetpath) count = int(result.getOutput(0)) arcpy.SetProgressor('step', '8_收集分组号', 0, count, 1) mergeFzhList = collecteUnionFzh(targetpath, fzhlist, unionfzhlist, targetValueDict) arcpy.AddMessage("8_数据更新") result = arcpy.GetCount_management(targetpath) count = int(result.getOutput(0)) arcpy.SetProgressor('step', '8_数据更新', 0, count, 1) updateTarget(targetpath, unionfzhlist, targetValueDict, mergeFzhList)
value = u'自主举证图斑' return value def judgeBHLX(shuvary,shpvary) if __name__ == "__main__": arcpy.AddMessage("12_开始添加字段") xzkpath = arcpy.GetParameterAsText(0) searchFields = ['OLDTAG','ZZJZTB','TBLX',"TBYBH",'TBWYM',"TSTYBM",'shuvary','shpvary',"BHLX"] arcpyDeal.ensureFields(xzkpath,searchFields) count = int(arcpy.GetCount_management(targetpath).getOutput(0)) arcpy.SetProgressor('step',"12_字段值更新",0,count,1) number = 0 with arcpy.da.UpdateCursor(targetpath,searchFields) as UpdateCursor: for updaterow in UpdateCursor: number += 1 data = dict(zip(searchFields,updaterow)) oldTag = data["OLDTAG"]
def UpdateTarget(xzkpath, datas): """更新还原初始库属性""" bsmDifference = [] zldwdmDifference = [] sjdlbmDifference = [] czcsxmDifference = [] tstybmDifference = [] arcpyDeal.ensureFields(xzkpath, ["cskmianji"], type="DOUBLE") fields = [ "TSTYBM", "cskbsm", "cskzldwdm", "cskdlbm", "cskczcsxm", "cskmianji", "BSM", "ZLDWDM", "SJDLBM", "CZCSXM" ] arcpyDeal.ensureFields(xzkpath, fields) fields.append("SHAPE@AREA") cursor = arcpy.da.UpdateCursor(xzkpath, fields, where_clause=" TSTYBM is not null", sql_clause=(None, 'ORDER BY TSTYBM')) for row in cursor: arcpy.SetProgressorPosition() tstybm = row[0] if tstybm not in datas: tstybmDifference.append(tstybm) row[1] = row[6] row[2] = row[7] row[3] = row[8] row[4] = row[9] row[5] = row[10] cursor.updateRow(row) continue if datas[tstybm]["cskbsm"] != datas[tstybm]["xzkbsm"]: bsmDifference.append(tstybm) if datas[tstybm]["cskzldwdm"] != datas[tstybm]["xzkzldwdm"]: zldwdmDifference.append(tstybm) if datas[tstybm]["cskdlbm"] != datas[tstybm]["xzksjdlbm"]: sjdlbmDifference.append(tstybm) zldwdmDifference.append(tstybm) if datas[tstybm]["cskczcsxm"] != datas[tstybm]["xzkczcsxm"]: czcsxmDifference.append(tstybm) row[1] = datas[tstybm]["cskbsm"] row[2] = datas[tstybm]["cskzldwdm"] row[3] = datas[tstybm]["cskdlbm"] row[4] = datas[tstybm]["cskczcsxm"] row[5] = datas[tstybm]["cskmianji"] cursor.updateRow(row) arcpy.AddMessage("3_共有%s个图斑无初始库图斑" % (len(tstybmDifference))) arcpy.AddMessage("3_共有%s个图斑bsm不同" % (len(bsmDifference))) arcpy.AddMessage("3_共有%s个图斑zldwdm不同" % (len(zldwdmDifference))) arcpy.AddMessage("3_共有%s个图斑sjdlbm不同" % (len(sjdlbmDifference))) arcpy.AddMessage("3_共有%s个图斑czcsxm不同" % (len(czcsxmDifference)))
def ensureSHFields(targetpath): fields = ["DLBM_1", "GDZZSXMC_1", "TBXHMC_1", "GDLX_1"] arcpyDeal.ensureFields(targetpath, fields)
continue else: lstbsm[cskbsm] = 0 arcpy.AddMessage('总共{0}个标识码'.format(len(lstbsm))) num = 0 for x in lstbsm: num = num + 1 lstbsm[x] = num arcpyDeal.ensureFields(xzkPath, ['xzkfzh'], 'LONG') xzkcur = arcpy.da.UpdateCursor(xzkPath, ['cskbsm', 'xzkfzh']) for row in xzkcur: cskbsm = row[0] row[1] = lstbsm[cskbsm] xzkcur.updateRow(row) arcpy.SetParameterAsText(1, xzkPath) arcpy.AddMessage('9_初始分组完成')