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)