使用 R 从网格创建点

Create points from a grid using R

我希望实现一个 .csv 文件,其中包含与 plot 上每个网格正方形的中心对应的坐标列表。

我已经能够映射 polygon 并覆盖 grid,但是我不确定 a) 每个网格正方形中心的绘图点需要什么,和 b) 从点中提取坐标 - 尽管一旦 a) 完成后后者应该会消失。

网格图如下:

如有任何建议,我们将不胜感激。

  First we need to make a regular grid
      NGSA.grid=spsample(NGSA.union, n = 1000, type="regular", nsig = 2,    offset = c(0.5,0.5),pretty = FALSE)
      str(NGSA.grid)
      gridded(NGSA.grid)=TRUE
      plot(NGSA.grid,pch=19,cex=0.1,col="green",axes=TRUE)
      plot(NGSA.OGR, add=TRUE, pch=16, cex=0.5)
      proj4string(NGSA.grid)==proj4string(NGSA.OGR)

首先按照 ?readOGR 创建我将在此处使用的 scot_BNG 对象。

然后创建网格对象:

> scotgrid = spsample(scot_BNG, n=1000, type="regular", nsig=2, pretty=FALSE)
> gridded(scotgrid)=TRUE

然后 coordinates 函数为您提供网格中心。请注意,在 将其设为 gridded 对象之前,您可以只使用在 上面创建的 scotgrid 对象。那时它是一个 SpatialPoints 对象。不管怎样:

> head(coordinates(scotgrid))
           x1       x2
[1,] 211728.1 535835.7
[2,] 247407.1 535835.7
[3,] 238487.4 544755.4
[4,] 247407.1 544755.4
[5,] 265246.6 544755.4
[6,] 274166.3 544755.4

如果你想在网格上绘制单元格中心,你可以使用 points,它在绘制之前提取这些单元格坐标:

> plot(scotgrid)
> points(scotgrid,pch=19,col="red",cex=.25)