在 R 中绘制全球投影栅格
Plot global projected raster in R
我正在尝试在 Equal Earth 投影中绘制全球(经度:-180- 180;纬度 -90- 90)栅格(无关紧要 - 可以是 Winkel Tripel 或 Robinson),但边界重复两侧(见图)。我怎样才能避免这种情况?
This SO question and this thread 给出的答案仅适用于在 Mollweide 中绘图,但不适用于其他投影。
这是一个可重现的例子。
library(maptools)
library(raster)
data("wrld_simpl")
r <- raster(ncol=180, nrow=90)
r <- rasterize(wrld_simpl, r, field="UN")
world_ext = projectExtent(wrld_simpl, crs = '+proj=longlat +datum=WGS84 +no_defs ')
r <- crop(x = r, y = world_ext, snap= 'in')
r <- projectRaster(r, crs = crs("+proj=wintri"), over = T)
plot(r)
非常感谢!
您可以为此使用 terra::project
中的 mask=TRUE
参数
library(maptools)
library(terra)
data("wrld_simpl")
w <- vect(wrld_simpl)
r <- rast(ncol=180, nrow=90)
r <- rasterize(w, r, field="UN")
x <- project(r, "+proj=wintri", mask=TRUE)
我正在尝试在 Equal Earth 投影中绘制全球(经度:-180- 180;纬度 -90- 90)栅格(无关紧要 - 可以是 Winkel Tripel 或 Robinson),但边界重复两侧(见图)。我怎样才能避免这种情况?
This SO question and this thread 给出的答案仅适用于在 Mollweide 中绘图,但不适用于其他投影。
这是一个可重现的例子。
library(maptools)
library(raster)
data("wrld_simpl")
r <- raster(ncol=180, nrow=90)
r <- rasterize(wrld_simpl, r, field="UN")
world_ext = projectExtent(wrld_simpl, crs = '+proj=longlat +datum=WGS84 +no_defs ')
r <- crop(x = r, y = world_ext, snap= 'in')
r <- projectRaster(r, crs = crs("+proj=wintri"), over = T)
plot(r)
非常感谢!
您可以为此使用 terra::project
中的 mask=TRUE
参数
library(maptools)
library(terra)
data("wrld_simpl")
w <- vect(wrld_simpl)
r <- rast(ncol=180, nrow=90)
r <- rasterize(w, r, field="UN")
x <- project(r, "+proj=wintri", mask=TRUE)