如何定义六边形网格的单元大小?

huangapple go评论64阅读模式
英文:

How define the cell size from a hexagonal grid?

问题

我试图从生态区边界(cerrado,但也适用于任何其他政治边界)创建一个六边形网格。在sf文档中,我看到可以使用st_make_grid函数来实现,但没有明确说明如何定义单元格的大小。我想要创建一个面积为25平方公里的六边形网格。

我尝试使用以下函数:

grid = sf::st_make_grid(x = shpCerrado, cellsize = 0.4, square = FALSE)

我使用了大小为0.4,因为一位朋友在QGis中进行了比较,并告诉我这个大小有25米的边。但我们不确定单元格的总面积(我们希望它是25平方公里)。

我尝试寻找一些包的文档或其他教程,解释如何定义六边形网格的单元格面积,但我找不到。有人知道如何进行这个计算吗?或者是否有其他方法在R中创建这个网格?

英文:

I'm trying to create a hexagonal grid from a biome boundaries (cerrado, but it could be able to apply to any other political boundaries). In sf documentation I saw that it is possible to do it with the st_make_grid function, but does not clear how the size cell are defined. I would like to make a hexagonal grid with 25km2 size cell.

I've tried to use this function:

> grid = sf::st_make_grid(x= shpCerrado, cellsize = 0.4, square = FALSE)

I used the size 0.4 because a friend compared in QGis and told that this size had a 25m side. But we dont have sure about the total area of the cell (which we would like that was 25km2).

I tried to find some package docs or another tutorial that explained how to define the cell area of a hexagonal grid, but I couldn't. Does anyone know how this calculation could be done? Or is there another way to make this grid in R?

答案1

得分: 1

你可以从六边形的面积通用公式推导出目标单元格大小;通过一点代数运算,你会得到 sqrt(2*cell_area/sqrt(3))

或者考虑这段代码;它覆盖了来自 nc.shp(随 {sf} 一起提供的)的亚斯县,在一个25平方千米的网格中。

library(sf)
library(dplyr)

nc <- st_read(system.file("shape/nc.shp", package="sf")) %>%
  slice(1) %>%
  st_geometry() %>%
  st_transform(3857) # 转换为度量CRS

cell_area <- units::as_units(25, "km^2") # 目标网格大小

grid_spacing <- sqrt(2*cell_area/sqrt(3)) # 从面积计算的六边形大小

grid <- nc %>%
  st_make_grid(square = FALSE, cellsize = grid_spacing)  # 创建网格

plot(nc, col = "red")
plot(grid, add = TRUE)

如何定义六边形网格的单元大小?


<details>
<summary>英文:</summary>

You can derive the target cell size from the generic formula for area of hexagon; with a little algebra you will arrive at `sqrt(2*cell_area/sqrt(3))`

Or consider this piece of code; it covers county Ashe from the well known `nc.shp` that ships with `{sf}` in a 25 km&#178; grid.

```r
library(sf)
library(dplyr)

nc &lt;- st_read(system.file(&quot;shape/nc.shp&quot;, package=&quot;sf&quot;)) %&gt;% 
  slice(1) %&gt;% # coiunty Ashe only
  st_geometry() %&gt;% # no need for data anymore
  st_transform(3857) # transform to a metric CRS 

cell_area &lt;- units::as_units(25, &quot;km^2&quot;) # target grid size

grid_spacing &lt;- sqrt(2*cell_area/sqrt(3)) # size of hexagon calculated from area

grid &lt;- nc %&gt;% 
  st_make_grid(square = F, cellsize = grid_spacing)  # make the grid
  
plot(nc, col = &quot;red&quot;)
plot(grid, add = T)

如何定义六边形网格的单元大小?

huangapple
  • 本文由 发表于 2023年5月7日 01:21:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76190186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定