r - 移动 sf 对象的经度
问题描述
我有一张国家地图(sf 对象),我想改变俄罗斯东部的经度,使其不与俄罗斯其他地区隔离。 看图片
我找到了st_shift_longitude
https://github.com/r-spatial/sf/blob/master/R/shift_longitude.R的后端代码,它将所有坐标移动了 180 度,因此生成的地图如下所示:
link
如何修改此代码块以仅移动俄罗斯东部?
shift_lon <- function(x){
xcrs = st_crs(x)
g = (x + c(360, 90)) %% c(360) - c(0, 90)
st_wrap_dateline(st_set_crs(g - c(180, 0), xcrs)) + c(180, 0)
st_set_crs(g, xcrs)
}
st_geometry(countries) <- shift_lon(st_geometry(countries))
也欢迎替代解决方案。
解决方案
您需要将您的world
对象分解为两部分 - 一部分包含俄罗斯,另一部分包含世界其他部分。
然后在俄罗斯部分应用太平洋视图/ sf::st_shift_longitude()
,并将其与“世界其他地区”数据集合并。
在此示例中,我使用giscoR
包中的世界数据集。这是我最喜欢的,但不是唯一可用的;并且它有一个功能(或错误,取决于具体情况)在 antimeridean 处应用薄中断;这导致在我的地图中楚科奇周围出现人工制品。摆脱它是一个单独的问题,我不确定您是否会使用您的世界数据集版本来面对它(因此它可能是相关问题,也可能不是相关问题)。
无论如何,这是一个可能的代码实现:
library(sf)
world <- giscoR::gisco_get_countries() # or your own world dataset
rossiya <- subset(world, ISO3_CODE == "RUS")
# shift Russia to a more Pacific centric worldview
pacified_rossiya <- st_shift_longitude(rossiya)
rest_of_world <- subset(world, ISO3_CODE != "RUS")
# this is the important section: bind together the shifted and unshifted parts
world2 <- rbind(pacified_rossiya,
rest_of_world)
plot(st_geometry(world2))
推荐阅读
- android - TabLayout 总是显示最后一个片段
- excel - VBA 变体索引超出范围
- c++ - 使用 CreateProcess 和 CoCreateInstance 创建 COM 组件
- python - TensorFlow Dataset.flat_map() 导致批次不均
- azure - Azure VM - 重新部署 VM
- rpm - 我们如何重命名 rpm 版本?
- javascript - 如何获得对 api 的身份验证
- android - 如何使用 ViewModel 存储位图列表以便在生命周期更改中生存?
- php - 使用 shell_exec 写入通过 PHP 调用的 Python 文本文件
- r - 为什么“digits”参数不影响 print(summary(fit)) 的输出?