R中从数据框到栅格的不规则网格 数据

我以不规则的间隔提取了点(纬度和经度)的数据。可以从提取数据框中创建不规则网格吗?我不打算插入数据并保持原样。 我在尝试创建网格数据集时遇到错误-

      lon     lat   temp
1  8.5261 50.0223 293.40
2 78.4390 17.2290 295.90
3  8.6350 49.9290 282.88
spg <- df
coordinates(spg) <- ~ lon + lat
gridded(spg) <- TRUE

points2grid(points,tolerance,round) 中的错误: 维度 1:坐标间隔不是恒定的

chyumkps198371 回答:R中从数据框到栅格的不规则网格 数据

我们可以round这些值

library(sp)
spg[1:2] <- lapply(spg[1:2],function(x) as.numeric(round(x)))
coordinates(spg) <- ~ lon + lat
gridded(spg) <- TRUE

-输出

> spg
Object of class SpatialPixelsDataFrame
Object of class SpatialPixels
Grid topology:
    cellcentre.offset cellsize cells.dim
lon                 9       69         2
lat                17       33         2
SpatialPoints:
  lon lat
1   9  50
2  78  17
3   9  50
Coordinate Reference System (CRS) arguments: NA 

Data summary:
      temp      
 Min.   :282.9  
 1st Qu.:288.1  
 Median :293.4  
 Mean   :290.7  
 3rd Qu.:294.6  
 Max.   :295.9  

数据

df <- structure(list(lon = c(8.5261,78.439,8.635),lat = c(50.0223,17.229,49.929),temp = c(293.4,295.9,282.88)),class = "data.frame",row.names = c("1","2","3"))
本文链接:https://www.f2er.com/666.html

大家都在问