首页 > 解决方案 > 移动 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))

也欢迎替代解决方案。

标签: rgeospatiallatitude-longitudesf

解决方案


您需要将您的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))

在此处输入图像描述


推荐阅读