[英]Convert a spatial point to raster in R
How to convert a single spatial point to a raster object.如何将单个空间点转换为栅格 object。 I want to create a raster of 0.1 resolution within the domain
xmin = 150 xmx=180,ymin=25,ymax=35
and put the values of a datapoint dt
point in the raster.我想在域
xmin = 150 xmx=180,ymin=25,ymax=35
内创建一个分辨率为 0.1 的栅格,并将数据点dt
点的值放入栅格中。
Here is the data and code.这是数据和代码。
dt<-data.frame(lon=71.85,lat =31.12,val=3)
dt
ras_dom<-raster(xmn=150, xmx=180, ymn=25, ymx=35,
crs="+proj=longlat +datum=WGS84 +no_defs ",
resolution=c(0.1,0.1), vals=NA)
ras_dom
I want to put the value (or values) from dt
in the ras_dom
so that I have a raster with values for given grids and NA
for others.我想将
dt
中的值(或值)放在ras_dom
中,以便我有一个栅格,其中包含给定网格的值和其他网格的NA
。
library(raster)
coordinates(dt) <- ~ lon + lat # Convert data frame to spatial object
result <- rasterize(dt, ras_dom, "val", update = TRUE) # put point in raster
result # The resulting raster with the point added
Because dt
in the example is outside the raster, result
does not contain it.由于示例中的
dt
在栅格之外, result
不包含它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.