使用点 shapefile 将更精细的栅格数据聚合到 25 公里的网格

Aggregating finer raster data to 25-km grid using a point shapefile

我有一系列来自 25 公里网格的点 shapefile 的经纬度

lon <- c(-53.615449969, -53.365449969, -53.115449969, -53.365449969, 
         -53.115449969, -52.865449969, -53.365449969, -53.115449969, -52.865449969, 
         -52.615449969, -53.365449969, -53.115449969, -52.865449969, -52.615449969, 
         -52.365449969, -53.365449969, -53.115449969, -52.865449969, -52.615449969, 
         -52.365449969, -53.615449969, -53.365449969, -53.115449969, -52.865449969, 
         -52.615449969, -52.365449969, -52.115449969, -53.865449969, -53.615449969, 
         -53.365449969, -53.115449969, -52.865449969, -52.615449969, -52.365449969, 
         -52.115449969, -51.865449969, -54.365449969, -54.115449969, -53.865449969, 
         -53.615449969, -53.365449969, -53.115449969, -52.865449969, -52.615449969, 
         -52.365449969, -52.115449969, -51.865449969, -51.615449969, -54.615449969, 
         -54.365449969, -54.115449969, -53.865449969, -53.615449969, -53.365449969, 
         -53.115449969, -52.865449969, -52.615449969, -52.365449969, -52.115449969, 
         -51.615449969)


lat <- c(-33.627081271, -33.627081271, -33.627081271, -33.377081271, 
         -33.377081271, -33.377081271, -33.127081271, -33.127081271, -33.127081271, 
         -33.127081271, -32.877081271, -32.877081271, -32.877081271, -32.877081271, 
         -32.877081271, -32.627081271, -32.627081271, -32.627081271, -32.627081271, 
         -32.627081271, -32.377081271, -32.377081271, -32.377081271, -32.377081271, 
         -32.377081271, -32.377081271, -32.377081271, -32.127081271, -32.127081271, 
         -32.127081271, -32.127081271, -32.127081271, -32.127081271, -32.127081271, 
         -32.127081271, -32.127081271, -31.877081271, -31.877081271, -31.877081271, 
         -31.877081271, -31.877081271, -31.877081271, -31.877081271, -31.877081271, 
         -31.877081271, -31.877081271, -31.877081271, -31.877081271, -31.627081271, 
         -31.627081271, -31.627081271, -31.627081271, -31.627081271, -31.627081271, 
         -31.627081271, -31.627081271, -31.627081271, -31.627081271, -31.627081271, 
        -31.627081271)

  df <- as.data.frame(cbind(lon, lat))
  df$ID <- 1:nrow(df)
  coordinates(df) <- c(1,2)
  plot(df, pch = 0)

为什么方块没有相互接触?我想如果这是一个 25 公里的网格,所有的方块应该共享它们各自的边界。

您创建的是一个 SpatialPointsDataFrame - 当您 plot 它时,您会得到以这些点为中心的标记。使用 pch=0 使用方形标记,但它不知道数据是规则网格。您可以绘制不同大小的标记 - 尝试:

plot(df, pch = 0, cex=6)
plot(df, pch = 0, cex=0.5)

或使用不同的标记:

plot(df, pch="Z")