简体   繁体   English

使用 R 从网格创建点

[英]Create points from a grid using R

I hope to achieve a .csv file with a list of coordinates corresponding to the centre of each grid square on a plot .我希望实现一个.csv文件,其中包含与plot上每个网格方块中心相对应的坐标列表。

I've been able to map the polygon and overlay a grid , however I'm not sure what will be required to a) plot points in the centre of each grid square, and b) extract the coordinates from the points - although the later should fall out once a) is complete.我已经能够映射polygon并覆盖一个grid ,但是我不确定 a) 在每个网格方块的中心绘制点,以及 b) 从这些点中提取坐标 - 尽管后者应该在 a) 完成后脱落。

Grid Plot is shown below:网格图如下所示:

网格图

Any suggestions would be appreciated.任何建议,将不胜感激。

  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)

First follow ?readOGR to create the scot_BNG object which I'll be using here.首先按照?readOGR创建scot_BNG对象,我将在这里使用它。

Then create gridded object:然后创建网格对象:

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

Then the coordinates function gets you the grid centres.然后coordinates函数为您提供网格中心。 Note you could just use the scotgrid object created above before you made it a gridded object.请注意,在将其scotgrid gridded对象之前,您可以只使用上面创建的scotgrid对象。 At that point its a SpatialPoints object.此时它是一个SpatialPoints对象。 Anyway:反正:

> 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

And if you want to plot the cell centres over the grid you can just use points , which extracts those cell coordinates before plotting:如果你想在网格上绘制单元格中心,你可以使用points ,它在绘制之前提取这些单元格坐标:

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

网格单元中的点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM