You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何消除跨180度经线的多面体内部分界线(基于sf包)

消除极地投影地图中俄罗斯跨180度经线的内部分界线

我尝试用spData包的world数据集制作极地投影地图,整体效果不错,但俄罗斯跨180度经线的区域有内部分界线,用st_union()没法消除,求用sf包优先的解决方案优化地图。

library(sf)
library(spData)
library(dplyr)
library(ggplot2)

# polygon to crop the countries to only the northernmost ones
crop_poly <- tibble(geometry = st_sfc(st_point(c(0, 90)),
                                      crs = 'EPSG:4326')) %>%
  st_sf() %>%
  st_transform(crs = 'EPSG:3413') %>%
  st_buffer(dist = 3909167) %>%
  smoothr::densify(n = 3) %>%
  st_transform(crs = 'EPSG:4326')

# crop the world dataset
world_north <- world %>%
  st_intersection(crop_poly) %>%
  st_transform(crs = 'EPSG:3413') %>%
  select(name_long, continent, region_un, subregion) %>%
  st_union(by_feature = TRUE) # this is the suggested method for dissolving internal boundaries

# make the map
ggplot(world_north) +
  geom_sf(data = crop_poly,
          color = 'transparent',
          fill = 'gray90',
          alpha = 0.5) +
  geom_sf(color = 'black', fill = 'gray80') +
  geom_sf(data = crop_poly, 
          color = 'gray70',
          fill = 'transparent',
          inherit.aes = FALSE) +
# add an arrow to highlight location of undesired internal boundaries
  geom_segment(x = 0, xend = -1300000,
               y = 0, yend = 1300000,
               arrow = arrow(),
               color = 'red') +
  theme_bw()
  

地图效果

已尝试的其他方法

  • 试过st_wrap_dateline(),但不确定适用场景,没找到可行用法
  • 尝试过EPSG:32635、st_union()和st_simplify()的多种组合,内部分界线仍未消除

解决方案

核心是先处理跨日界线的多边形拓扑,再执行裁剪和投影,避免投影后多边形分裂导致无法合并。以下是基于sf包的可行方案:

library(sf)
library(spData)
library(dplyr)
library(ggplot2)
library(smoothr)

# 预处理跨日界线多边形,确保俄罗斯等国家的几何图形连续
world_processed <- world %>%
  st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180")) %>%
  st_make_valid() # 修复潜在拓扑错误

# 制作裁剪多边形(保留原逻辑)
crop_poly <- tibble(geometry = st_sfc(st_point(c(0, 90)),
                                      crs = 'EPSG:4326')) %>%
  st_sf() %>%
  st_transform(crs = 'EPSG:3413') %>%
  st_buffer(dist = 3909167) %>%
  densify(n = 3) %>%
  st_transform(crs = 'EPSG:4326')

# 裁剪、投影并合并内部界线
world_north <- world_processed %>%
  st_intersection(crop_poly) %>%
  st_transform(crs = 'EPSG:3413') %>%
  select(name_long, continent, region_un, subregion) %>%
  st_union(by_feature = TRUE)

# 绘制优化后的地图
ggplot(world_north) +
  geom_sf(data = crop_poly,
          color = 'transparent',
          fill = 'gray90',
          alpha = 0.5) +
  geom_sf(color = 'black', fill = 'gray80') +
  geom_sf(data = crop_poly, 
          color = 'gray70',
          fill = 'transparent',
          inherit.aes = FALSE) +
  theme_bw()

关键要点

  • st_wrap_dateline()通过指定日界线参数,将跨180度经线的多边形强制包裹为单一连续图形,避免分裂为两部分
  • st_make_valid()用于修复处理后可能出现的拓扑问题,确保后续空间操作正常执行
  • 必须先处理日界线问题,再进行裁剪和投影——若先投影,分裂的多边形会因坐标系统变化无法通过st_union()合并

内容的提问来源于stack exchange,提问作者Heidi Rodenhizer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 13:50:35