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 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 deleteFields(targetpath): """删除过程字段""" delFieldsList = [ "unionfzh", "exp_bsm", "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", "intersecrteddeal" ] arcpyDeal.deleteFields(targetpath, delFieldsList)
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 dissolve2(xzkpath, dissolvepath, outputxzkpath): """融合相同属性数据""" arcpy.Dissolve_management(xzkpath, dissolvepath, 'dlbm;zldwdm;gdlx;tbxhdm;gdzzsxdm;xzkfzh', '', 'SINGLE_PART', 'UNSPLIT_LINES') arcpyDeal.deleteFields(dissolvepath, ['ZLDWDM', 'DLBM', 'GDLX', 'TBXHDM', 'GDZZSXDM']) # arcpy.SpatialJoin_analysis(target_features=dissolvepath, join_features=xzkpath, out_feature_class=outputxzkpath, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_COMMON", field_mapping="""bsm_list "bsm_list" true true false 1024 Text 0 0 ,Join,",",%s,cskbsm,-1,-1;cskbsm "cskbsm" true true false 1024 Text 0 0 ,First,#,%s,cskbsm,-1,-1"""%(xzkpath,xzkpath), match_option="CONTAINS", search_radius="", distance_field_name="") arcpy.SpatialJoin_analysis(target_features=dissolvepath, join_features=xzkpath, out_feature_class=outputxzkpath, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_ALL", field_mapping=""" ZLDWDM "ZLDWDM" true true false 255 Text 0 0 ,First,#,%s,ZLDWDM,-1,-1; DLBM "DLBM" true true false 255 Text 0 0 ,First,#,%s,DLBM,-1,-1; GDLX "GDLX" true true false 255 Text 0 0 ,First,#,%s,GDLX,-1,-1; TBXHDM "TBXHDM" true true false 255 Text 0 0 ,First,#,%s,TBXHDM,-1,-1; GDZZSXDM "GDZZSXDM" true true false 255 Text 0 0 ,First,#,%s,GDZZSXDM,-1,-1; xzkfzh "xzkfzh" true true false 10 Text 0 0 ,First,#,%s,xzkfzh,-1,-1; TSTYBM "TSTYBM" true true false 255 Text 0 0 ,First,#,%s,TSTYBM,-1,-1; BSM "BSM" true true false 255 Text 0 0 ,First,#,%s,BSM,-1,-1; JZSJ "JZSJ" true true false 255 Text 0 0 ,First,#,%s,JZSJ,-1,-1; WJZLX "WJZLX" true true false 255 Text 0 0 ,First,#,%s,WJZLX,-1,-1; CZCSXM "CZCSXM" true true false 255 Text 0 0 ,First,#,%s,CZCSXM,-1,-1; TBXHMC "TBXHMC" true true false 255 Text 0 0 ,First,#,%s,TBXHMC,-1,-1; GDZZSXMC "GDZZSXMC" true true false 255 Text 0 0 ,First,#,%s,GDZZSXMC,-1,-1; SJDLBM "SJDLBM" true true false 255 Text 0 0 ,First,#,%s,SJDLBM,-1,-1; width "width" true true false 8 Double 0 0 ,First,#,%s,width,-1,-1; cskmianji "cskmianji" true true false 8 Double 0 0 ,First,#,%s,cskmianji,-1,-1; cskbsm "cskbsm" true true false 255 Text 0 0 ,First,#,%s,cskbsm,-1,-1; cskzldwdm "cskzldwdm" true true false 255 Text 0 0 ,First,#,%s,cskzldwdm,-1,-1; cskdlbm "cskdlbm" true true false 255 Text 0 0 ,First,#,%s,cskdlbm,-1,-1; cskczcsxm "cskczcsxm" true true false 255 Text 0 0 ,First,#,%s,cskczcsxm,-1,-1; OLDTAG "OLDTAG" true true false 20 Text 0 0 ,First,",",%s,OLDTAG,-1,-1; ZZJZTB "ZZJZTB" true true false 10 Text 0 0 ,First,",",%s,ZZJZTB,-1,-1; bsm_list "bsm_list" true true false 1024 Text 0 0 ,Join,",",%s,cskbsm,-1,-1; tstybmlist "tstybmlist" true true false 2000 Text 0 0 ,Join,",",%s,TSTYBM,-1,-1; """ % (xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath), match_option="CONTAINS") arcpy.MakeFeatureLayer_management(outputxzkpath, "test")
def dissolve1(xzkpath, dissolvepath, outputxzkpath1): """融合相同属性,bsm一致的图斑,保证只有属性变化的图斑与周边图斑不在同一个分组号内""" arcpy.CheckGeometry_management(xzkpath, "dissolvepath_7_CheckGeometry") searchFields = ['cskbsm', 'dlbm', 'zldwdm', 'gdlx', 'tbxhdm', 'gdzzsxdm'] arcpy.AddMessage("融合字段:" + ';'.join(searchFields)) arcpy.Dissolve_management(xzkpath, dissolvepath1, "ZLDWDM;DLBM;GDLX;TBXHDM;GDZZSXDM;cskbsm", "#", "SINGLE_PART", "UNSPLIT_LINES") arcpyDeal.deleteFields(dissolvepath1, searchFields) arcpy.SpatialJoin_analysis( dissolvepath1, xzkpath, outputxzkpath1, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_ALL", match_option="CONTAINS", field_mapping=""" DLBM "DLBM" true true false 5 Text 0 0 ,First,#,%s,DLBM,-1,-1; ZLDWDM "ZLDWDM" true true false 19 Text 0 0 ,First,#,%s,ZLDWDM,-1,-1; GDLX "GDLX" true true false 2 Text 0 0 ,First,#,%s,GDLX,-1,-1; TBXHDM "TBXHDM" true true false 4 Text 0 0 ,First,#,%s,TBXHDM,-1,-1; GDZZSXDM "GDZZSXDM" true true false 8 Text 0 0 ,First,#,%s,GDZZSXDM,-1,-1; LINKTBS "LINKTBS" true true false 254 Text 0 0 ,First,#,%s,LINKTBS,-1,-1; TBXHMC "TBXHMC" true true false 20 Text 0 0 ,First,#,%s,TBXHMC,-1,-1; GDZZSXMC "GDZZSXMC" true true false 20 Text 0 0 ,First,#,%s,GDZZSXMC,-1,-1; CZCSXM "CZCSXM" true true false 4 Text 0 0 ,First,#,%s,CZCSXM,-1,-1; TSTYBM "TSTYBM" true true false 100 Text 0 0 ,First,#,%s,TSTYBM,-1,-1; SJDLBM "SJDLBM" true true false 100 Text 0 0 ,First,#,%s,SJDLBM,-1,-1; OLDTAG "OLDTAG" true true false 20 Text 0 0 ,First,#,%s,OLDTAG,-1,-1; JZSJ "JZSJ" true true false 8 Date 0 0 ,First,#,%s,JZSJ,-1,-1; BSM "BSM" true true false 18 Text 0 0 ,First,#,%s,BSM,-1,-1; ZZJZTB "ZZJZTB" true true false 1 Text 0 0 ,First,#,%s,ZZJZTB,-1,-1; WJZLX "WJZLX" true true false 8 Text 0 0 ,First,#,%s,WJZLX,-1,-1; cskmianji "cskmianji" true true false 8 Double 0 0 ,First,#,%s,cskmianji,-1,-1; cskbsm "cskbsm" true true false 255 Text 0 0 ,First,#,%s,cskbsm,-1,-1; cskzldwdm "cskzldwdm" true true false 255 Text 0 0 ,First,#,%s,cskzldwdm,-1,-1; cskdlbm "cskdlbm" true true false 255 Text 0 0 ,First,#,%s,cskdlbm,-1,-1; cskczcsxm "cskczcsxm" true true false 255 Text 0 0 ,First,#,%s,cskczcsxm,-1,-1; tstybmlist "tstybmlist" true true false 2000 Text 0 0 ,Join,",",%s,TSTYBM,-1,-1;""" % (xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath, xzkpath))
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)