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

如何在R中用ETRS89/ETRS-LAEA投影替换等地球投影?

解决方案:替换地图坐标系为ETRS89 / ETRS-LAEA

核心修改

你只需要修改代码中定义目标坐标系的那一行即可。ETRS89 / ETRS-LAEA对应的EPSG代码是3035,sf包可以直接识别这个代码,无需手动编写完整的proj字符串。

修改后的完整代码

library(tidyverse)
library(rnaturalearth)
library(sf)

ww_ini <- ne_countries(scale = "medium",
                       type = 'countries',
                       returnclass = "sf")

bb <- ne_download(type = "wgs84_bounding_box", category = "physical",
                  returnclass = "sf") 

## Step 1: 替换为ETRS89 / ETRS-LAEA坐标系(EPSG:3035)
target_crs <- 3035

## Step 2: 转换世界数据到新坐标系
worldmap_trans <- st_transform(ww_ini, crs = target_crs)

### Step 3: 定义WGS84下的显示窗口
disp_win_wgs84 <- st_sfc(st_point(c(-20, 30)), st_point(c(45, 73)),
                         crs = 4326)

## Step 4: 转换显示窗口到新坐标系
disp_win_trans <- st_transform(disp_win_wgs84, crs = target_crs)

#### Step 5: 获取新坐标系下的窗口坐标
disp_win_coord <- st_coordinates(disp_win_trans)

## 绘制地图
gpl <- ggplot() + geom_sf(data = worldmap_trans) +
    coord_sf(xlim = disp_win_coord[,'X'], ylim = disp_win_coord[,'Y'],
             datum = target_crs, expand = FALSE) +
    theme_bw()

gpl

补充说明

  • 你的环境中PROJ版本为9.1.1,完全支持EPSG:3035投影,无需额外配置。
  • 使用EPSG代码比手动编写proj字符串更简洁且不易出错,sf会自动从PROJ数据库中加载对应的投影参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 12:27:05