根据东北大西洋的拖网数据,我有一个纬度和经度值的矢量。不幸的是,没有关于这些立场的深入资料。我在想,我可以用getNOAA.bathy (R中的MARMAP包)生成深度信息。这个包还有一个名为get.depth()的函数,它允许用户单击地图并在该位置生成深度。
所以我的问题是,我能不能自动生成一个深度向量,由我的lat和lon向量自动生成,而不需要点击每一个的地图(我有700个条目要做)?
##load package
library(marmap)
## generate bathymetric data
bio_depth<-getNOAA.bathy(-25, -5, 50, 68)
## vectors of lat, lon (reduced sample for demo purposes)
lat<-c(54.487, 54.487, 54.487, 54.535, 54.535)
lon<-c(-5.187, -5.187, -5.187, -5.267, -5.267)发布于 2014-02-20 11:57:53
是的,这可能比你想象的要容易。您创建的bio_depth矩阵实际上只是一个包含所有深度的大矩阵,其中的纬度和经度作为行名和列名。所以你可以像这样直接提取深度:
library(marmap)
## generate bathymetric data
bio_depth<-getNOAA.bathy(-25, -5, 50, 68)
## vectors of lat, lon (reduced sample for demo purposes)
lat<-c(54.487, 54.487, 54.487, 54.535, 54.535)
lon<-c(-5.187, -5.187, -5.187, -5.267, -5.267)
# Grab the lat/long from the row names
mat.lon <- as.numeric(rownames(bio_depth))
mat.lat <- as.numeric(colnames(bio_depth))
# For each lat/long, exact matches are unlikely, find the range
# in which each one falls.
x<-findInterval(lon,mat.lon)
y<-findInterval(lat,mat.lat)
# Find depth of each lat/long
bio_depth[cbind(x,y)]
# [1] -108 -108 -108 -108 -108发布于 2014-04-11 11:06:50
现在可以使用来自marmap 0.8和更高版本的新的marmap 0.8函数来完成这项工作。你所要做的就是:
library(marmap)
## generate bathymetric data
bio_depth<-getNOAA.bathy(-25, -5, 50, 68)
## vectors of lat, lon (reduced sample for demo purposes)
lat<-c(54.487, 54.487, 54.487, 54.535, 54.535)
lon<-c(-5.187, -5.187, -5.187, -5.267, -5.267)
get.depth(bio_depth, x=lon, y=lat, locator=F)
# Lon Lat Depth
# 1 -5.187 54.487 -108
# 2 -5.187 54.487 -108
# 3 -5.187 54.487 -108
# 4 -5.267 54.535 -126
# 5 -5.267 54.535 -126https://stackoverflow.com/questions/21904816
复制相似问题