全球地理距离栅格 [英] Global Raster of geographic distances

查看:68
本文介绍了全球地理距离栅格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人建立了世界各大洲的栅格,其中每个像元等于该像元到最近海岸的距离.该地图将突出显示内陆最偏远的陆地区域.

Im wondering if someone has built a raster of the continents of the world where each cell equals the distance of that cell cell to the nearest shore. This map would highlight the land areas that are most isolated inland.

我想这会简单地 rasterize 全局边界的shapefile,然后计算距离.

I would imagine this would simply rasterize a shapefile of the global boundaries and then calculate the distances.

推荐答案

您可以使用 raster :: distance 进行此操作,该方法计算从每个 NA 单元格到最接近的非 NA 单元格.您只需创建一个栅格,该栅格的陆地像素具有 NA ,非陆地像素具有一些其他值.

You can do this with raster::distance, which calculates the distance from each NA cell to the closest non-NA cell. You just need to create a raster that has NA for land pixels, and some other value for non-land pixels.

方法如下:

library(raster)
library(maptools)
data(wrld_simpl)

# Create a raster template for rasterizing the polys. 
# (set the desired grid resolution with res)
r <- raster(xmn=-180, xmx=180, ymn=-90, ymx=90, res=1)

# Rasterize and set land pixels to NA
r2 <- rasterize(wrld_simpl, r, 1)
r3 <- mask(is.na(r2), r2, maskvalue=1, updatevalue=NA)

# Calculate distance to nearest non-NA pixel
d <- distance(r3)

# Optionally set non-land pixels to NA (otherwise values are "distance to non-land")
d <- d*r2

要创建上面的绘图(我喜欢 rasterVis 进行绘图,但是您可以使用 plot(r)):

To create the plot above (I like rasterVis for plotting, but you could use plot(r)):

library(rasterVis)
levelplot(d/1000, margin=FALSE, at=seq(0, maxValue(d)/1000, length=100),
          colorkey=list(height=0.6), main='Distance to coast')

这篇关于全球地理距离栅格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆