ArcPy修改字段值

修改字段值(注册版本时需要开启编辑)
file_names=(‘BOUAN’,’BOULK’,’BOUNT’,’BOUPT’,’CTRLK’,’CTRPT’,’HYDAN’,’HYDLK’,’HYDNT’,’HYDPT’,’PIPAN’,’PIPLK’,’PIPNT’,’PIPPT’,’RESAN’,’RESLK’,’RESNT’,’RESPT’,’ROAAN’,’ROALK’,’ROANT’,’ROAPT’,’TERAN’,’TERLK’,’TERNT’,’TERPT’,’VEGAN’,’VEGLK’,’VEGNT’,’VEGPT’)
… target_folder = ‘D:\T20161202’
… symbolRef_field=’SYMBOLREF’
… where_clause= u”GlobalID IS NOT NULL”
… fields = [‘GLOBALID’,’SymbolRef’]
… arcpy.env.workspace=r’Database Connections/Connection to Orcl.sde’
… workspace = arcpy.env.workspace
… editor = arcpy.da.Editor(workspace)
… sde_datasets = arcpy.ListDatasets()
… for sde_dataset in sde_datasets:
…     sde_ds_names = sde_dataset.split(‘.’)
…     sde_ds_user = sde_ds_names[0]
…     if sde_ds_user==’GYJCCH’:
…         for sde_fc in arcpy.ListFeatureClasses(feature_dataset=sde_dataset):
…             print sde_fc
…             sde_fc_names = os.path.split(sde_fc)
…             sde_fc_fullnames = sde_fc_names[1].split(‘.’)
…             sde_fc_name = sde_fc_fullnames[1]
…             sde_fc_shortname = sde_fc_name[-5:]
…             if sde_fc_shortname in file_names and sde_fc_name[0:10]==’DLG_K_CGY_’:
…                 file_name_ext = sde_fc_shortname+’.txt’
…                 file_path = os.path.join(target_folder,file_name_ext)
…                 print file_path
…                 if os.path.exists(file_path):
…                     open_file=open(file_path,’r’)
…                     editor.startEditing(False,True)
…                     editor.startOperation()
…                     updateCursor = arcpy.da.UpdateCursor(sde_fc,fields,where_clause,None)
…                     for row in updateCursor:
…                         for file_line in open_file:
…                             guid_sub = file_line[0:38]
…                             if guid_sub == row[0]:
…                                 symbolref_value = file_line[39:-1]
…                                 row[1]=symbolref_value
…                                 updateCursor.updateRow(row)
…                                 print (‘Updated : GlobaldID = {0}, SymbolRef = {1}’.format(guid_sub,symbolref_value))
…                     del updateCursor
…                     editor.stopOperation()
…                     editor.stopEditing(True)
备注:未注册归档时不需要editor

转载自:https://blog.csdn.net/a_dev/article/details/54344405

You may also like...