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

Irregular grid from dataframe to raster in 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 : 坐标间隔不恒定


我们可以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"))