我正在使用来自拉丁美洲 WorldClim V2.1(30 秒分辨率)的环境栅格图层。我希望图层具有精确的分辨率(50km2 像素大小)。但是,我有点不确定我是否按照正确的步骤来处理文件。任何有关检查过程的帮助将不胜感激。
最后一件事,我想知道 s 在terra::resample
做什么NA
。谢谢 !
这是一个年平均温度的例子
图书馆
library(rnaturalearth)
library(terra)
library(sf)
library(tidyverse)
底图
# world and Latin America
world <- rnaturalearth::ne_countries(scale = 'medium', returnclass = 'sf')
bbox_Latam_unprojected <- c(xmin=-118.40137, ymin=-55.89170, xmax=-34.80547, ymax= 32.71533)
Latam_unprojected <- world %>% st_crop(bbox_Latam_unprojected)
# equal area projection (Equatorial Lambert azimuthal equal-area)
equalareaCRS <- '+proj=laea +lon_0=-73.125 +lat_0=0 +datum=WGS84 +units=m +no_defs'
Latam_projected <- sf::st_transform(Latam_unprojected, crs=equalareaCRS)
Latam <- st_union(Latam_projected)
# raster of Latin America to use as template - 50km^2 (50000m^2)
Latam.grid <- st_make_grid(Latam+1000, cellsize = 50000, crs = equalareaCRS) %>%
st_sf('geometry' = ., 'occ'= 0)
r <- rast(res=50000, ext(vect(Latam.grid)), crs=equalareaCRS)
Latam.raster <- terra::rasterize(x = vect(Latam.grid),
y = r, field = 'occ') %>% terra::mask(., vect(Latam))
环境层
# annual temperature files
url <- 'https://biogeo.ucdavis.edu/data/worldclim/v2.1/base/wc2.1_30s_tavg.zip'
download.file(url, destfile='data/wc2.1_30s_tavg')
# average annual temperature
tavg_files <- list.files('data/wc2.1_30s_tavg', '.tif', full.names=TRUE)
world_tavg <- rast(tavg_files)
tavg_unprojected <- crop(world_tavg, ext(Latam_unprojected)+1)
tavg <- project(tavg_unprojected, equalareaCRS, method='near') # reproject to equal area
tavg <- mean(tavg)
names(tavg) <- 'tavg'
# resample to Latam's preferred resolution
tavg_Latam <- terra::resample(tavg, Latam.raster, method='bilinear')
关注
class : SpatRaster
dimensions : 12512, 11213, 1 (nrow, ncol, nlyr)
resolution : 829.4488, 829.4488 (x, y)
extent : -5009004, 4291606, -6411068, 3966996 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=laea +lat_0=0 +lon_0=-73.125 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
source : tavg.tif
name : tavg
min value : -15.775
max value : 29.56667
tavg_Latam
class : SpatRaster
dimensions : 199, 172, 1 (nrow, ncol, nlyr)
resolution : 50000, 50000 (x, y)
extent : -4409882, 4190118, -6080809, 3869191 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=laea +lat_0=0 +lon_0=-73.125 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
source : memory
name : tavg
min value : -2.684936
max value : 29.17986
干杯,弗洛