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 dealNull(xzkPath, cskPath): """清理空值并更新MC值""" searchFields = [ 'bsm', 'dlbm', 'dlmc', 'gdlx', 'tbxhdm', 'tbxhmc', 'gdzzsxdm', 'gdzzsxmc', 'czcsxm', 'wjzlx', 'LINKTBS' ] xzkcur = arcpy.da.UpdateCursor(xzkPath, searchFields) for row in xzkcur: #去除空值 for i in range(len(searchFields)): if row[i] != None and row[i] in (u"0"): row[i] = "" else: row[i] = dealNone.dealNoneAndBlank(row[i]) #更新mc值 dlbm = row[1] tbxhdm = row[4] gdzzsxdm = row[6] row[2] = relation.getMC(dlbm) row[5] = relation.getMC(tbxhdm) row[7] = relation.getMC(gdzzsxdm) xzkcur.updateRow(row) arcpy.SetProgressorPosition() searchFields = ['bsm', 'dlbm', 'czcsxm'] cskcur = arcpy.da.UpdateCursor(cskPath, searchFields) for row in cskcur: for i in range(len(searchFields)): row[i] = dealNone.dealNoneAndBlank(row[i]) cskcur.updateRow(row) arcpy.SetProgressorPosition()
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 createTempDatasLimit(searchFields,tempFields,targetpath,datas,where_clause = "",sql_clause = (None,None),offset=0,limit=100000): checkField(targetpath,searchFields) number = -1 for row in arcpy.da.SearchCursor(targetpath, searchFields,where_clause = where_clause,sql_clause = sql_clause): number += 1 if number < offset: continue data = {} for i in range(len(tempFields)): data[tempFields[i]] = dealNone.dealNoneAndBlank(row[i]) datas.append(data) if len(datas) >= limit: break
def get(datas, targetValueList): for data in datas: if dealNone.dealNoneAndBlank(data["TSTYBM"]) != "": targetValueList.append(data["TSTYBM"])
def UpdateDats(jzzp): updateCurosr = arcpy.da.UpdateCursor(jzzp, [ 'WJZLX', 'NAME', 'PSR', 'AZIM', 'ROLL', 'TILT', 'PICX', 'PICY', 'FJLX', 'FJFW' ]) for updateRow in updateCurosr: WJZLX = dealNone.dealNoneAndBlank(updateRow[0]) if WJZLX == "": updateRow[0] = "" else: updateRow[1] = "" updateRow[2] = "" updateRow[3] = 0 updateRow[4] = 0 updateRow[5] = 0 updateRow[6] = 0 updateRow[7] = 0 updateRow[8] = "" updateRow[9] = "" updateCurosr.updateRow(updateRow) arcpy.SetProgressorPosition()
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 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 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 createTempDatas(searchFields,tempFields,targetpath,datas,where_clause = "",sql_clause = (None,None)): """根据输入字段和条件SQL筛选数据,并把每条记录构建成dict格式""" checkField(targetpath,searchFields) for row in arcpy.da.SearchCursor(targetpath, searchFields,where_clause = where_clause,sql_clause = sql_clause): data = {} for i in range(len(tempFields)): data[tempFields[i]] = dealNone.dealNoneAndBlank(row[i]) datas.append(data)
def searchClip(indentitypath): """查找规则而临时标识图层,确认哪些图斑存在几何变化""" where_clause = " SHAPE_Area > 10" sql_clause = (None, "ORDER BY BSM,TSTYBM DESC") searchFields = ["BSM", "TSTYBM"] cursor = arcpy.da.SearchCursor(indentitypath, searchFields, where_clause=where_clause, sql_clause=sql_clause) lastdata = {} falsebsm = "" datas = [] targetValueList = [] for row in cursor: data = dict(zip(searchFields, row)) if data["BSM"] == falsebsm: continue else: falsebsm = "" if lastdata == {}: lastdata = data elif lastdata["BSM"] != data["BSM"]: get(datas, targetValueList) datas = [] lastdata = data if dealNone.dealNoneAndBlank(data["TSTYBM"]) == "": falsebsm == data["BSM"] datas.append(data) return targetValueList
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 start(targetpath, outname): arcpyDeal.createExistsTempLayer(targetpath, outname) cursor = arcpy.da.UpdateCursor(outname, ["bhlx"]) result = arcpy.GetCount_management(outname) count = int(result.getOutput(0)) arcpy.SetProgressor('step', '遍历进度', 0, count, 1) for row in cursor: bhlx = dealNone.dealNoneAndBlank(row[0]) if bhlx == "": cursor.deleteRow() arcpy.SetProgressorPosition()
def updateDatas(targetpath): """更新图层的细化代码和属性值""" searchFields = [ 'DLBM_1', "WJZLX", "CZCSXM_1", 'exp_sjdlbm', 'GDLX', 'TBXHDM', 'TBXHMC', 'GDZZSXDM', 'GDZZSXMC', "DLBM_12", "GDZZSXMC_1", "GDLX_1", "TBXHMC_1", "exp_wjzlx", "exp_czcsxm", 'bhlx', "exp_dlbm", "exp_dlmc", "exp_gdzzsxdm", "exp_gdzzsxmc", "exp_gdlx", "exp_tbxhdm", "exp_tbxhmc" ] tempFields = [ 'dlbm', "wjzlx", "czcsxm", 'exp_sjdlbm', 'gdlx', 'tbxhdm', 'tbxhmc', 'gdzzsxdm', 'gdzzsxmc', "dlbm_1", "gdzzsxmc_1", "gdlx_1", "tbxhmc_1", "exp_wjzlx", "exp_czcsxm", 'bhlx', "exp_dlbm", "exp_dlmc", "exp_gdzzsxdm", "exp_gdzzsxmc", "exp_gdlx", "exp_tbxhdm", "exp_tbxhmc" ] arcpyDeal.checkField(targetpath, searchFields) list = [field.name for field in arcpy.ListFields(targetpath)] with arcpy.da.UpdateCursor(targetpath, searchFields) as UpdateCursor: for updaterow in UpdateCursor: data = dict(zip(tempFields, updaterow)) dlbm = dealNone.dealNoneAndBlank(data['dlbm']) exp_sjdlbm = dealNone.dealNoneAndBlank(data['exp_sjdlbm']) czcsxm = dealNone.dealNoneAndBlank(data['czcsxm']) wjzlx = dealNone.dealNoneAndBlank(data['wjzlx']) gdlx = dealNone.dealNoneAndBlank(data['gdlx']) tbxhdm = dealNone.dealNoneAndBlank(data['tbxhdm']) tbxhmc = dealNone.dealNoneAndBlank(data['tbxhmc']) gdzzsxdm = dealNone.dealNoneAndBlank(data['gdzzsxdm']) gdzzsxmc = dealNone.dealNoneAndBlank(data['gdzzsxmc']) dlbm_1 = dealNone.dealNoneAndBlank(data['dlbm_1']) gdzzsxmc_1 = dealNone.dealNoneAndBlank(data['gdzzsxmc_1']) gdlx_1 = dealNone.dealNoneAndBlank(data['gdlx_1']) tbxhmc_1 = dealNone.dealNoneAndBlank(data['tbxhmc_1']) #创建临时值,如果省级审核有内容,则把省级审核信息输出 nullValue = ["", None, u"无", "0"] tempwjzlx = wjzlx tempczcsxm = czcsxm tempdlbm = dlbm if dlbm_1 in nullValue else dlbm_1 tempgdzzsxmc = gdzzsxmc if gdzzsxmc_1 in nullValue else gdzzsxmc_1 tempgdlx = gdlx if gdlx_1 in nullValue else gdlx_1 temptbxhmc = tbxhmc if tbxhmc_1 in nullValue else tbxhmc_1 #获取变化类型 checkValue = [["ZZSXMC", tempgdzzsxmc], ["GDLXMC", tempgdlx], ["TBXHMC", temptbxhmc]] bhlx = getBhlx(checkValue, nullValue, tempdlbm, exp_sjdlbm) #根据临时值还原所有属性 exp_wjzlx, exp_czcsxm, exp_dlbm, exp_dlmc, exp_gdzzsxdm, exp_gdzzsxmc, exp_gdlx, exp_tbxhdm, exp_tbxhmc = getAllNewValue( tempwjzlx, tempczcsxm, tempdlbm, tempgdzzsxmc, tempgdlx, temptbxhmc) #所有 updaterow[-10] = exp_wjzlx updaterow[-9] = exp_czcsxm updaterow[-8] = bhlx updaterow[-7] = exp_dlbm updaterow[-6] = exp_dlmc updaterow[-5] = exp_gdzzsxdm updaterow[-4] = exp_gdzzsxmc updaterow[-3] = exp_gdlx updaterow[-2] = exp_tbxhdm updaterow[-1] = exp_tbxhmc UpdateCursor.updateRow(updaterow) arcpy.SetProgressorPosition()
def collecteFzh(targetpath, targetdatas, fzhlist, targetValueDict): """收集分组和变化类型""" linktbsLack = [] mergeFzhList = {} for i in range(len(targetdatas)): targetdata = targetdatas[i] targettstybm1 = dealNone.dealNoneAndBlank(targetdata['TSTYBM']) targetlinktbs1 = dealNone.dealNoneAndBlank(targetdata['linktbs']) targetbhlx1 = dealNone.dealNoneAndBlank(targetdata['bhlx']) #分析存在LINKTBS的图斑的变化类型 targetNewBhlx1 = BhlxRules(targetbhlx1) targetfzh1 = "" if targettstybm1 in targetValueDict: targetfzh1 = targetValueDict[targettstybm1]['fzh'] targetValueDict[targettstybm1]['bhlx'] = targetNewBhlx1 #查找LINKTBS对应图斑数据 where_clause = "bsm = '%s' and TSTYBM <> '%s'" % (targetlinktbs1, targettstybm1) targetdatas2 = [] searchFields = ["TSTYBM", 'bhlx'] tempFields = ["TSTYBM", 'bhlx'] arcpyDeal.createTempDatas(searchFields, tempFields, targetpath, targetdatas2, where_clause=where_clause) #遍历图斑,分析LinkTBS对应的图斑的变化类型;分析存在LINKTBS的图斑和对应图斑的分组号 for targetdata2 in targetdatas2: targettstybm2 = dealNone.dealNoneAndBlank(targetdata2['TSTYBM']) targetbhlx2 = dealNone.dealNoneAndBlank(targetdata2['bhlx']) targetNewBhlx2 = BhlxRules(targetbhlx2) targetValueDict[targettstybm2]['bhlx'] = targetNewBhlx2 targetfzh2 = "" if targettstybm2 in targetValueDict: targetfzh2 = targetValueDict[targettstybm1]['fzh'] if targetfzh1 == "" and targetfzh2 == "": newFzh = getNewFzh(fzhlist) targetfzh1 = newFzh targetfzh2 = newFzh elif targetfzh1 == "" and targetfzh2 != "": targetfzh1 = targetfzh2 elif targetfzh1 != "" and targetfzh2 == "": targetfzh2 = targetfzh1 elif targetfzh1 != "" and targetfzh2 != "" and targetfzh1 != targetfzh2: mergeFzhByFzh(targetfzh1, targetfzh2, fzhlist, mergeFzhList) targetValueDict[targettstybm1]['fzh'] = targetfzh1 targetValueDict[targettstybm2]['fzh'] = targetfzh2 arcpy.SetProgressorPosition() if len(targetdatas2) == 0: linktbsLack.append(targettstybm1) arcpy.AddMessage("5_共有%s个图斑存在LINKTBS但无法找到对应BSM图斑" % (len(linktbsLack))) return mergeFzhList
def collecteFzh(targetpath, targetdatas, fzhlist, targetValueDict, targetValueList): """收集分组和变化类型""" mergeFzhList = {} lastdata = {} for i in range(len(targetdatas)): targetdata = targetdatas[i] targettstybm = dealNone.dealNoneAndBlank(targetdata['TSTYBM']) targetexp_bsm = dealNone.dealNoneAndBlank(targetdata['exp_bsm']) targetbhlx = dealNone.dealNoneAndBlank(targetdata['bhlx']) #分析存在LINKTBS的图斑的变化类型 targetfzh = targetValueDict[targettstybm]['fzh'] if lastdata == {}: lastdata = targetdata continue #查找两个相邻图斑判断exp_bsm是否一致 lastexp_bsm = dealNone.dealNoneAndBlank(lastdata['exp_bsm']) lasttstybm = dealNone.dealNoneAndBlank(lastdata['TSTYBM']) lastbhlx = dealNone.dealNoneAndBlank(lastdata['bhlx']) lastfzh = targetValueDict[lasttstybm]['fzh'] if targetexp_bsm == lastexp_bsm: if targetfzh == "" and lastfzh == "": newFzh = getNewFzh(fzhlist) targetfzh = newFzh lastfzh = newFzh elif targetfzh == "" and lastfzh != "": targetfzh = lastfzh elif targetfzh != "" and lastfzh == "": lastfzh = targetfzh elif targetfzh != "" and lastfzh != "" and targetfzh != lastfzh: mergeFzhByFzh(targetfzh, lastfzh, fzhlist, mergeFzhList) targetValueDict[targettstybm]['bhlx'] = BhlxRules( targettstybm, targetValueList, targetbhlx) targetValueDict[lasttstybm]['bhlx'] = BhlxRules( lasttstybm, targetValueList, lastbhlx) targetValueDict[targettstybm]['fzh'] = targetfzh targetValueDict[lasttstybm]['fzh'] = lastfzh lastdata = targetdata arcpy.SetProgressorPosition() return mergeFzhList
cur.execute(sql) arcpy.AddMessage(sql) shyjList = cur.fetchall() cur.close() shyjDict = {} arcpy.SetProgressor('step','构造查询结果数据',0,len(shyjList),1) for i in range(len(shyjList)): TSTYBM = dealNone.dealNoneAndBlank(shyjList[i][0]) SHDLBM = dealNone.dealNoneAndBlank(shyjList[i][1]) SHGDLX = dealNone.dealNoneAndBlank(shyjList[i][2]) SHTBXHMC = dealNone.dealNoneAndBlank(shyjList[i][3]) SHZZSXMC = dealNone.dealNoneAndBlank(shyjList[i][4]) SHTBXHDM = relation.getDM(SHTBXHMC) SHZZSXDM = relation.getDM(SHZZSXMC) shyjDict[TSTYBM] = {"SHDLBM":SHDLBM,"SHGDLX":SHGDLX,"SHTBXHDM":SHTBXHDM,"SHZZSXDM":SHZZSXDM} arcpy.SetProgressorPosition() arcpy.SetProgressor('step','更新数据',0,int(arcpy.GetCount_management("byztb").getOutput(0)),1) with arcpy.da.UpdateCursor("byztb",["TSTYBM","DLBM","GDLX","TBXHDM","GDZZSXDM"]) as cur: