[英]Joining tables to a raster attribute table to create new raster with the reclassified values python or R
我正在嘗試將具有柵格分類的.csv文件加入,以使用新信息創建柵格。
.csv文件中的PatchID對應於柵格DN。
.csv文件如下所示:
PatchID area shape_index
0 11592800 24.78
1 2556440 7.02
2 3562800 14.70
3 2945450 2.48
4 3892610 6.36
5 7678785680 11.68
6 1756784547 2.43
柵格看起來像:
0 0 0 0 0 0 1 1 1 1 0
0 0 2 2 0 0 1 1 0 0 0
0 0 0 2 2 0 0 0 0 3 3
0 0 2 0 2 0 4 4 0 3 3
0 0 0 0 2 0 0 4 0 0 3
0 5 0 0 0 0 4 4 0 0 0
0 5 5 5 0 0 0 0 0 6 6
新的柵格應如下所示:
24.78 24.78 24.78 24.78 24.78 24.78 7.02 7.02 7.02 7.02 24.78
24.78 24.78 14.70 14.70 24.78 24.78 7.02 7.02 24.78 24.78 24.78
24.78 24.78 24.78 14.70 14.70 24.78 24.78 24.78 24.78 2.48 2.48
24.78 24.78 14.70 24.78 14.70 24.78 6.36 6.36 24.78 2.48 2.48
24.78 24.78 24.78 24.78 14.70 24.78 24.78 6.36 24.78 24.78 2.48
24.78 11.68 24.78 24.78 24.78 24.78 6.36 6.36 24.78 24.78 24.78
24.78 11.68 11.68 11.68 24.78 24.78 24.78 24.78 24.78 2.43 2.43
我可以通過將柵格多邊形化並將表格連接到shapefile來完成這項工作,但是此過程需要占用大量CPU。
這里是一個簡單快速的解決方案(無需加入):
t((matrix(df[,"shape_index"][as.vector(m)+1],nrow=11,ncol=7)))
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 24.78 24.78 24.78 24.78 24.78 24.78 7.02 7.02 7.02 7.02 24.78
[2,] 24.78 24.78 14.70 14.70 24.78 24.78 7.02 7.02 24.78 24.78 24.78
[3,] 24.78 24.78 24.78 14.70 14.70 24.78 24.78 24.78 24.78 2.48 2.48
[4,] 24.78 24.78 14.70 24.78 14.70 24.78 6.36 6.36 24.78 2.48 2.48
[5,] 24.78 24.78 24.78 24.78 14.70 24.78 24.78 6.36 24.78 24.78 2.48
[6,] 24.78 11.68 24.78 24.78 24.78 24.78 6.36 6.36 24.78 24.78 24.78
[7,] 24.78 11.68 11.68 11.68 24.78 24.78 24.78 24.78 24.78 2.43 2.43
在這段代碼中,我使用m
中的值作為df$shape_index
的位置[+1調整]
輸入數據:
df<-data.frame(PatchID=c(0,1,2,3,4,5,6),
area=c(11592800,2556440,3562800,2945450,3892610,7678785680,1756784547),
shape_index=c(24.78,7.02,14.70,2.48,6.36,11.68,2.43))
m<-matrix(c(0,0,0,0,0,0,1,1,1,1,0,
0,0,2,2,0,0,1,1,0,0,0,
0,0,0,2,2,0,0,0,0,3,3,
0,0,2,0,2,0,4,4,0,3,3,
0,0,0,0,2,0,0,4,0,0,3,
0,5,0,0,0,0,4,4,0,0,0,
0,5,5,5,0,0,0,0,0,6,6),nrow=7,ncol=11)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.