我有两个栅格(第一个是从 www.worldpop.org 下载的网格化人口计数 GeoTIFF 栅格,另一个是 GADM 1 级数据(这是国家/省/地区的索引),它是转换为 R 中的栅格)。
假设我在从 here 下载的 30 弧秒分辨率 tif 文件中选择了以色列和该国 2020 年联合国调整后的人口数。
Router
library(raster)
library(rgdal)
library(terra)
rm(list = ls())
#----------------------------------------------------------------#
# Source 1: WorldPop UN-Adjusted Population Count GeoTIFF raster #
#----------------------------------------------------------------#
# Import the GeoTIFF file into R workspace
url <- "https://data.worldpop.org/GIS/Population/Global_2000_2020_1km_UNadj/2020/ISR/isr_ppp_2020_1km_Aggregated_UNadj.tif"
fname <- basename(url)
if (!file.exists(fname)) download.file(url, fname, mode="wb")
WorldPop <- raster("fname")
WorldPop <- replace(WorldPop, is.na(WorldPop), 0)
WorldPop
dim(WorldPop)
plot(rast("fname"), main = "2020 UN-Adjusted Population Count for Israel", col=rev(rainbow(10, end=0.7)), breaks=c(0, 10, 25, 50, 100, 250, 1000, 100000))
inhabitableRaster <- WorldPop
values(inhabitableRaster) <- ifelse(values(WorldPop) > 0, 1, 0)
names(inhabitableRaster) <- "Inhabitable"
inhabitableRaster
dim(inhabitableRaster)
table(as.matrix(inhabitableRaster))
plot(inhabitableRaster, main = "Inhabitable Status (0 = uninhabitable / 1 = inhabitable)")
#---------------------------------------#
# Source 2: From GADM: Level1Identifier #
#---------------------------------------#
Level1Identifier <- getData("GADM", level=1, country="ISR")
Level1Identifier$NAME_1 # List of all states/provinces/regions
Level1Raster <- raster(Level1Identifier, resolution = res(WorldPop)[1])
Level1Raster <- rasterize(Level1Identifier, Level1Raster)
Level1Raster <- crop(Level1Raster, WorldPop)
names(Level1Raster) <- "Level1Identifier"
table(values(Level1Raster))
plot(Level1Raster)
我希望 Level1Raster 与 WorldPop 栅格具有相同的维度。这怎么办?
我可以将 Level1Raster 的原点设置为 WorldPop 的原点,但这不会将 GADM 栅格的维度(nrow x ncols)更改为 匹配 WorldPop 人口计数栅格。< /p>
crs(Level1Raster)
crs(WorldPop)
origin(Level1Raster)
origin(WorldPop)
extent(Level1Raster)
extent(WorldPop)
res(Level1Raster)
res(WorldPop)
dim(Level1Raster)
dim(WorldPop)
我也尝试了以下
origin(Level1Raster) <- origin(WorldPop)
dim(Level1Raster)
dim(WorldPop)
以上代码行将 WorldPop 的列/行从 (474, 200) 更改为 Level1Raster 的 (464, 196)。但是,我希望反过来,我希望 Level1Raster 维度与 WorldPop 相同。