我一直在使用这个有用的链接来学习从 R 中的 WorldClim 2.1 中提取生物气候变量:https://www.benjaminbell.co.uk/2018/01/extracting-data-and-making-climate-maps.html ?lr=1
当从 14 个 GPS 点提取高程值时,我发现 WorldClim 2.1 找到的高程值与我在 GPS 或 Google Earth 上获得的高程值不匹配。有时它们会偏离数百米。下面是我的代码。
# Set working directory to look at elevation (this contains "wc2.1_30s_elev.tif" from WorldClim 2.1):
setwd("/Users/XXXX/Desktop/WorldClim 2.1")
# Create raster layers for elevation
elev <- raster("wc2.1_30s_elev.tif")
# Create a data frame with sample site coordinates for Costa Rica and Panama
site <- c("PN Volcan Tenorio", "Rara Avis", "RB El Copal", "PN La Cangreja", "La Chaqueta", "San Isidro", "Las Cruces", "Risco Abajo", "La Fortuna", "Santa Fe", "Altos de Maria", "Cerro Jefe", "Chucantí", "Altos de Campana")
lon <- c(-84.99, -84.04, -83.75, -84.36, -83.91, -83.62, -82.97, -82.50, -82.20, -81.14, -80.07, -79.40, -78.45, -79.92)
lat <- c(10.70, 10.28, 9.78, 9.71, 9.50, 9.43, 8.78, 9.19, 8.72, 8.52, 8.64, 9.23, 8.79, 8.69)
elevationsamples <- data.frame(site, lon, lat, row.names="site")
# Here, we created three vector objects containing our data, then we created the data frame object by telling R which vectors to use to construct the data frame.
# The vectors will become columns in the data frame.
# Specifying row.names="site" tells R that the "site" vector should be used for the row names in the data frame.
elevationsamples
# Extract data from WorldClim for your sites
elev.data <- elevationsamples
elev.data$elevation <- extract(elev, elevationsamples)
# Check to see what it looks like
elev.data
我想知道我在提取时是否做错了什么,或者是否有人知道 WorldClim 2.1 获得的高程值存在问题。
这不是一个编码问题(因此不适合本网站),因为下面的代码(带有一些示例数据的代码)按预期工作。
library(terra)
x <- rast(names="elevation")
values(x) <- 1:ncell(x)
# Create a data frame with sample site coordinates for Costa Rica and Panama
site <- c("PN Volcan Tenorio", "Rara Avis", "RB El Copal", "PN La Cangreja", "La Chaqueta", "San Isidro", "Las Cruces", "Risco Abajo", "La Fortuna", "Santa Fe", "Altos de Maria", "Cerro Jefe", "Chucantí", "Altos de Campana")
lon <- c(-84.99, -84.04, -83.75, -84.36, -83.91, -83.62, -82.97, -82.50, -82.20, -81.14, -80.07, -79.40, -78.45, -79.92)
lat <- c(10.70, 10.28, 9.78, 9.71, 9.50, 9.43, 8.78, 9.19, 8.72, 8.52, 8.64, 9.23, 8.79, 8.69)
elev <- data.frame(site, lon, lat, row.names="site")
elev$elevation <- extract(x, elev, ID=FALSE)
head(elev)
# lon lat elevation
#PN Volcan Tenorio -84.99 10.70 28536
#Rara Avis -84.04 10.28 28536
#RB El Copal -83.75 9.78 28897
#PN La Cangreja -84.36 9.71 28896
#La Chaqueta -83.91 9.50 28897
#San Isidro -83.62 9.43 28897
高程数据不匹配是预料之中的,因为几乎 1 x 1 公里的网格单元中高程可能存在很大变化。在陡峭的山区,肯定会出现几个 100m 的情况。