繁体   English   中英

在r中绘制栅格图层上的空间点

[英]plotting spatial points over a raster layer in r

我希望在将矩阵转换为栅格对象(tempMap)后绘制矩阵(temp_matrix)。 此外,我希望在同一个绘图窗口中添加几个可用于我的纬度和经度位置的点。 我尝试过几种方法,但似乎没有一种方法可行,因为可用点是lat / long中的特定位置,而我得到的栅格对象具有不同的范围。 请帮我解决这个问题。 下面给出了问题的示例数据。

library(raster)
temp_matrix<-array(NA,c(11,11))
temp_matrix[1,]<-c(NA,NA,NA,NA,NA,NA,NA,0,0,-6,-6)
temp_matrix[2,]<-c(0,0,0,0,NA,NA,1,0,0,0,0)
temp_matrix[3,]<-c(1,0,0,-1,-1,0,0,0,1,0,0)
temp_matrix[4,]<-c(1,1,0,0,0,0,-1,-1,0,0,0)
temp_matrix[5,]<-c(1,NA,NA,NA,NA,-1,-1,-1,0,-1,-1)
temp_matrix[6,]<-c(NA,NA,NA,NA,NA,NA,-1,-1,-1,0,0)
temp_matrix[7,]<-c(NA,NA,NA,NA,NA,NA,NA,0,-1,0,0)
temp_matrix[8,]<-c( NA,NA,NA,NA,NA,NA,NA,0,0,0,-1)
temp_matrix[9,]<-c(NA,NA,NA,NA,NA,NA,NA,-1,0,0,0)
temp_matrix[10,]<-c(NA,NA,NA,NA,NA,NA,NA,NA,-1,-1,-2)
temp_matrix[11,]<-c(NA,NA,NA,NA,NA,NA,NA,NA,-2,-3,-2)
plot(raster(temp_matrix),axes = FALSE,legend=FALSE)
tempMap <- raster(temp_matrix)

# plot the points over this raster layer
point_1<-c(10,10) # should appear on 2nd row from top i.e. over temp_matrix[2,10]
point_2<-c(9,10)  # should appear on 3rd row from top i.e. over temp_matrix[3,10]
point_3<-c(1,10)  # should appear on lowermost row i.e.over temp_matrix[11,10]

您需要设置所需的范围,而不是依赖于默认值。

作为raster状态的帮助

## S4 method for signature 'matrix'
raster(x, xmn=0, xmx=1, ymn=0, ymx=1, crs=NA, template=NULL)

  • xmn ::最小x坐标(左边框)

  • xmx ::最大x坐标(右边框)

  • ymn ::最小y坐标(下边框)

  • ymx ::最大y坐标(上边框)

您可以设置xmnxmxymnymx在这种情况下,你希望的值(1,11,1,11))

tempMap <- raster(temp_matrix, xmn = 1, xmx = 11, ymn = 1, ymx=11)
plot(tempMap,axes = FALSE,legend=FALSE)
points(c(10,9,1), c(10,10,10))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM