ArcMap表關聯Join中數據條數超過65536條快速解決辦法
Arcmap圖層需要對屬性表做Join操作時,默認只保留65536條記錄,多出的會被捨棄掉,可利用arcpy解決該問題,同時arcpy在進行字段計算時簡直是快到飛起!
以關連xls文件爲例,分爲兩步:
- 切分xls文件
- 編寫python
按照自身要求,將xls文件切分爲多個sheet,每個sheet中的記錄條數小於65536條,我這裏有6個sheet,每個sheet爲50000條記錄
然後保存(注意,需要保存成.xls)
打開Arcmap->地理處理(Geoprocessing)->Python,進入python對話窗口,關鍵代碼如下:
xlsPath = "C:/Users/Jason/Desktop/result.xls" #xls文件完整路徑
x1 = xlrd.open_workbook(xlsPath) #讀取xls文件
sheet1 = x1.sheet_by_name("Sheet1") #讀取sheet
cursor = arcpy.UpdateCursor("final_point","FID < 50000") #創建更新遊標FID < 50000爲查詢條件,以提高寫入效率,也可留空
for i in range(50000):
row = cursor.next()
row.setValue("Pre190227",sheet1.cell_value(i+1,1)) #爲目標字段賦值
cursor.updateRow(row) #更新記錄
這裏我需要賦值的字段爲Pre190227,賦值依據爲字段FID,因爲屬性表的記錄條數與xls能一一匹配,代碼中就沒有進行字段匹配判斷而是直接賦值,各位看官依照自生情況靈活參考:
完整代碼:
// An highlighted block
import arcpy #
import xlrd #用於讀取xls文件,arcgis自帶
xlsPath = "C:/Users/Jason/Desktop/result.xls" #xls文件完整路徑
x1 = xlrd.open_workbook(xlsPath) #讀取xls文件
sheet1 = x1.sheet_by_name("Sheet1") #讀取sheet
cursor = arcpy.UpdateCursor("final_point","FID < 50000") #創建更新遊標FID < 50000爲查詢條件,以提高寫入效率,也可留空
for i in range(50000):
row = cursor.next()
row.setValue("Pre190227",sheet1.cell_value(i+1,1)) #爲目標字段賦值
cursor.updateRow(row) #更新記錄
sheet2 = x1.sheet_by_name("Sheet2")
cursor = arcpy.UpdateCursor("final_point","FID >=50000 AND FID <100000")
for i in range(50000):
row = cursor.next()
row.setValue("Pre190227",sheet2.cell_value(i+1,1))
cursor.updateRow(row)
sheet3 = x1.sheet_by_name("Sheet3")
cursor = arcpy.UpdateCursor("final_point","FID >=100000 AND FID <150000")
for i in range(50000):
row = cursor.next()
row.setValue("Pre190227",sheet3.cell_value(i+1,1))
cursor.updateRow(row)
sheet4 = x1.sheet_by_name("Sheet4")
cursor = arcpy.UpdateCursor("final_point","FID >=150000 AND FID <200000")
for i in range(50000):
row = cursor.next()
row.setValue("Pre190227",sheet4.cell_value(i+1,1))
cursor.updateRow(row)
sheet5 = x1.sheet_by_name("Sheet5")
cursor = arcpy.UpdateCursor("final_point","FID >=200000 AND FID <250000")
for i in range(50000):
row = cursor.next()
row.setValue("Pre190227",sheet5.cell_value(i+1,1))
cursor.updateRow(row)
sheet6 = x1.sheet_by_name("Sheet6")
cursor = arcpy.UpdateCursor("final_point","FID >=250000")
for i in range(250000,294557):
row = cursor.next()
row.setValue("Pre190227",sheet6.cell_value(i-249999,1))
cursor.updateRow(row)