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

跨180°经线的多国/地区EEZ经纬网绘制问题求助

解决跨180°经线区域的经纬网绘制问题

问题背景

使用从marineregions.org下载的0-360版本全球EEZ shapefile(太平洋中心投影),绘制斐济等跨/临近180°经线区域的地图时,遇到以下问题:

  • 设定合理地理边界[170, 185,-25,-10]后,经纬网无法延伸至180°以东区域
  • 添加scale_x_continuous/scale_y_continuous手动设置刻度也无法解决
  • 扩大边界至[170,195,-25,-10]虽能正常显示经纬网,但会出现大量无关区域

解决方案

问题出在ggplot2默认的网格线生成逻辑无法适配0-360坐标系下的跨180°区域。无需更换投影,只需手动生成匹配当前边界的经纬网图层,替代默认网格即可。

关键操作

  • 根据设定的地理边界,生成自定义的经线和纬线sf对象
  • 在ggplot中添加自定义经纬网图层,同时关闭默认的panel.grid.major

修改后的完整代码

library(ggplot2)
library(sf)
library(maps)

# 读取0-360版本全球EEZ数据
ALL_EEZ <- sf::st_read(paste0(map.dir,"EEZ/eez_v12_0_360.shp"))
FJ_EEZ<- ALL_EEZ[ALL_EEZ$TERRITORY1=="Fiji",]

# 设定斐济的合理地理边界
geo_bounds<- c(170, 185,-25,-10) # 西经, 东经, 南纬, 北纬
ww=abs(geo_bounds[2]-geo_bounds[1])*100 # 窗口宽度
wh=abs(geo_bounds[4]-geo_bounds[3])*100 # 窗口高度

if (dev.cur()!=1) dev.off()
windows(ww,wh)

# --------------------------
# 生成自定义经纬网
# --------------------------
# 生成经线(间隔5°)
long_breaks <- seq(geo_bounds[1], geo_bounds[2], 5)
graticule_lines_x <- lapply(long_breaks, function(lon) {
  st_linestring(rbind(c(lon, geo_bounds[3]), c(lon, geo_bounds[4])))
})
graticule_x <- st_sfc(graticule_lines_x, crs = st_crs(ALL_EEZ))

# 生成纬线(间隔5°)
lat_breaks <- seq(geo_bounds[3], geo_bounds[4], 5)
graticule_lines_y <- lapply(lat_breaks, function(lat) {
  st_linestring(rbind(c(geo_bounds[1], lat), c(geo_bounds[2], lat)))
})
graticule_y <- st_sfc(graticule_lines_y, crs = st_crs(ALL_EEZ))

# 合并经纬网为sf对象
graticule <- st_sf(geometry = c(graticule_x, graticule_y))

# --------------------------
# 绘制地图
# --------------------------
gg1<-ggplot() + 
  # 添加自定义经纬网
  geom_sf(data = graticule, color = gray(.5), linetype = "dotted", linewidth = 0.3) +
  # 添加EEZ图层
  geom_sf(data = FJ_EEZ, colour = "black", fill=alpha("steelblue1",0.6), linewidth = 0.75) +
  # 设置地理边界
  coord_sf(xlim = c(geo_bounds[1],geo_bounds[2]), ylim = c(geo_bounds[3],geo_bounds[4])) +
  # 关闭默认网格线
  theme(panel.grid.major = element_blank(), panel.background = element_rect(fill = NA, colour="black"))

print(gg1)

说明

  • 手动生成的经纬网严格匹配设定的地理边界,不会受180°经线的截断影响
  • 通过st_crs确保自定义经纬网的坐标系与EEZ数据一致
  • 关闭默认的panel.grid.major避免重复绘制网格

内容的提问来源于stack exchange,提问作者Steven Hare

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 02:39:51