R语言:多值提取到点

ArcGIS中有相关工具实现多值提取到点的功能,在这里,我将使用R语言进行操作:

r 复制代码
library(dplyr)
library(readxl)
library(sf)
library(raster)

setwd("D:/Datasets")
Bio <- stack(paste0("D:/Datasets/Data/worldclim2_1km/",
                            c("wc2.1_30s_bio_1","wc2.1_30s_bio_2",
                              "wc2.1_30s_bio_3","wc2.1_30s_bio_4",
                              "wc2.1_30s_bio_5","wc2.1_30s_bio_6",
                              "wc2.1_30s_bio_7","wc2.1_30s_bio_8",
                              "wc2.1_30s_bio_9","wc2.1_30s_bio_10",
                              "wc2.1_30s_bio_11","wc2.1_30s_bio_12",
                              "wc2.1_30s_bio_13","wc2.1_30s_bio_14",
                              "wc2.1_30s_bio_15","wc2.1_30s_bio_16",
                              "wc2.1_30s_bio_17","wc2.1_30s_bio_18",
                              "wc2.1_30s_bio_19"
                            ),
                            ".tif")
)

dataset <- read_excel("datasets.xlsx")
head(dataset)

# 定义经纬度坐标
longlat<- as.data.frame(dataset[,c(2:3)])
# 将经纬度坐标转换为SpatialPoints对象
coordinates(longlat) <- c("Long", "Lat")
proj4string(longlat) <- CRS("+proj=longlat +datum=WGS84")
#定义转换的投影方式
UTM_Proj <- CRS(st_crs(Bio)$proj4string)
# 将经纬度坐标转换为xy坐标
xy <- spTransform(longlat, UTM_Proj)
# 检查投影坐标系是否一致
st_crs(Bio)$proj4string
st_crs(xy)$proj4string

data_clim<-raster::extract(Bio, xy)
head(data_clim)

这里Bio数据结果如下: 其中地理坐标系为WGS 1984,投影坐标系为WGS 1984 Albers(见crs

r 复制代码
> Bio
class      : RasterStack 
dimensions : 1422, 1185, 1685070, 19  (nrow, ncol, ncell, nlayers)
resolution : 1000, 1000  (x, y)
extent     : 296958.9, 1481959, 2562602, 3984602  (xmin, xmax, ymin, ymax)
crs        : +proj=aea +lat_0=0 +lon_0=105 +lat_1=25 +lat_2=47 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs 
names      : wc2.1_30s_bio_1, wc2.1_30s_bio_2, wc2.1_30s_bio_3, wc2.1_30s_bio_4, wc2.1_30s_bio_5, wc2.1_30s_bio_6, wc2.1_30s_bio_7, wc2.1_30s_bio_8, wc2.1_30s_bio_9, wc2.1_30s_bio_10, wc2.1_30s_bio_11, wc2.1_30s_bio_12, wc2.1_30s_bio_13, wc2.1_30s_bio_14, wc2.1_30s_bio_15, ... 
min values :        3.520833,        5.666667,       19.015659,      585.165588,       17.000000,      -11.500000,       24.199999,       12.566667,       -5.850000,        12.566667,        -5.850000,       533.000000,       109.000000,         2.000000,        41.892853, ... 
max values :        20.31667,        11.91667,        33.88480,      1056.25293,        34.50000,         6.20000,        38.90000,        27.73333,        17.23333,         28.71667,         12.00000,       2296.00000,        368.00000,         62.00000,        111.78159, ... 

注意: dataset中使用的采样点为度分表的小数形式,然而所需要提取的Bio数据为投影坐标系,所以这里需要为dataset采样点定义一个相同的投影坐标系,才能实现采样。

相关推荐
一点媛艺2 小时前
Kotlin函数由易到难
开发语言·python·kotlin
姑苏风2 小时前
《Kotlin实战》-附录
android·开发语言·kotlin
奋斗的小花生3 小时前
c++ 多态性
开发语言·c++
魔道不误砍柴功3 小时前
Java 中如何巧妙应用 Function 让方法复用性更强
java·开发语言·python
闲晨3 小时前
C++ 继承:代码传承的魔法棒,开启奇幻编程之旅
java·c语言·开发语言·c++·经验分享
老猿讲编程3 小时前
一个例子来说明Ada语言的实时性支持
开发语言·ada
Chrikk4 小时前
Go-性能调优实战案例
开发语言·后端·golang
幼儿园老大*4 小时前
Go的环境搭建以及GoLand安装教程
开发语言·经验分享·后端·golang·go
canyuemanyue4 小时前
go语言连续监控事件并回调处理
开发语言·后端·golang
杜杜的man4 小时前
【go从零单排】go语言中的指针
开发语言·后端·golang