如何生成所有国家的10x10km网格单元? [英] How to generate 10x10km grid cells of all countries?
问题描述
早上好
我目前正在尝试将10x10(或5x5)公里的国家(无海洋)网格单元固定到边界.例如,请参阅尼日利亚的栅格栅格:尼日利亚栅格像元
I am currently trying to get 10x10 (or 5x5) km grid cells of countries (no ocean) clipped to the borders. See for example a grid raster for Nigeria: Nigeria Grid Cells
计划A:我的计划是制作GADM 0级地图( https: //gadm.org/data.html )与国家/地区边界并相应地创建网格单元.
PLAN A: My plan was to take the GADM level 0 map (https://gadm.org/data.html) with country borders and create grid cells accordingly.
虽然st-grid命令很简单,但计算却要花一些时间(尼日利亚为30小时以上)
While the st-grid command is easy, it takes ages to calculate (>30h for Nigeria)
regions <- st_read("data/region/gadm36_0.shp") %>%
st_transform("+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
grid<- st_make_grid(regions %>%
st_union(), cellsize = c(10000, 10000), square = T)
即使使用R Studio Pro服务器也要花费很多时间...
Even with a R Studio Pro sever it is taking a lot of time...
有什么想法可以解决这个问题吗?
计划B:我的第二个计划是使用 https://figshare.com/articles/Global_10_x_10-km_grids_suitable_for_use_in_IUCN_Red_List_of_Ecosystems_assesssments_vector_and_raster_format_/4653439 并将其裁剪到GADM国家/地区形状文件中.
PLAN B: My second plan was to use the 10x10km grid raster from https://figshare.com/articles/Global_10_x_10-km_grids_suitable_for_use_in_IUCN_Red_List_of_Ecosystems_assessments_vector_and_raster_format_/4653439 and clip it to the GADM country shape file.
问题是我无法将栅格数据文件加载到R中,无法使其与sf包中的crop and mask命令一起运行. 有人知道如何进行此操作吗?
The problem is that I was not able to load the raster data file into R and to make it run with the crop and mask command from the sf package. Does anybody have an idea how to make this run?
计划C::对于已经存在的国家,是否有10x10公里的栅格栅格文件?我知道PRIO的50x50网格,但是找不到一个好的解决方案.
PLAN C: Is there a 10x10km grid raster file for countries that already exsists? I am aware of the 50x50 grid by PRIO but didn´t find a good solution.
非常感谢,希望您能帮助我解决此问题!
推荐答案
参考 PLAN A ,您可以使用stars::st_as_stars
创建栅格,然后使用stars::st_as_stars
代替栅格,然后将其转换为多边形sf::st_as_sf
,尼日利亚需要1-2秒:
Referring to PLAN A, instead of sf::st_make_grid
you can create a raster with stars::st_as_stars
and then transform it to polygons with sf::st_as_sf
, which takes 1-2 seconds for Nigeria:
library(sf)
library(stars)
library(rnaturalearth)
# Polygon
world = ne_countries(scale = "small", returnclass = "sf")
world = st_transform(world, "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
pol = world[world$sovereignt == "Nigeria", ]
# Make grid
grid = st_as_stars(st_bbox(pol), dx = 10000, dy = 10000)
grid = st_as_sf(grid)
grid = grid[pol, ]
# Plot
plot(st_geometry(grid), axes = TRUE, reset = FALSE)
plot(st_geometry(world), border = "grey", add = TRUE)
plot(st_geometry(pol), border = "red", add = TRUE)
参考 PLAN B ,可以将10公里的栅格导入R并使用包stars
进行裁剪,如下所示:
Referring to PLAN B, the 10-km raster can be imported into R and cropped also using package stars
, as follows:
library(sf)
library(stars)
library(rnaturalearth)
# Raster
r = read_stars("AOOGrid_10x10kmRast/AOOGrid_10x10km.img")
# Polygon
world = ne_countries(scale = "small", returnclass = "sf")
world = st_transform(world, st_crs(r))
pol = world[world$sovereignt == "Nigeria", ]
# Crop
r = r[pol]
# Plot
plot(r, axes = TRUE, reset = FALSE)
plot(st_geometry(world), border = "grey", add = TRUE)
plot(st_geometry(pol), add = TRUE)
这篇关于如何生成所有国家的10x10km网格单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!