library(sf)
library(tidyverse)
我有一个 sf 对象
geometry type:point
预计在太平洋上空
bbox: xmin: 0 ymin: -78 xmax: 359 ymax: 0 (WGS 84)
我想将 sf 对象从太平洋 View (0,360) 重新投影到大西洋中心 (-180,180)。我在sf包中发现了一个允许从大西洋 View 到太平洋 View 的函数(即st_shift_longitude(x)
)。但我想要的却恰恰相反......
帮忙?谢谢
最佳答案
如果没有一些数据的暗示,很难确定,但这是一种方法:
我假设点的原始 sf
对象没有设置 crs,因为经度 0-360 是不寻常的。下面的代码使用 -78-0 表示纬度,使用 0-360 表示经度组成一些数据点。设置了 "+proj=longlat +ellps=WGS84 +pm=-360 +datum=WGS84 +no_defs"
的(有点不寻常的)crs,然后将其转换为 lon/lat 数据的常用 4326 .
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
library(tidyverse)
set.seed(42) # for reporducibility
points <- tibble(x = sample(0:359, size = 20, replace = T),
y = sample(-78:0, size = 20, replace = T)) %>%
st_as_sf(coords = c("x", "y"), remove = F)
# Set a crs that understands 0-360 longitude
points <- st_set_crs(points, "+proj=longlat +ellps=WGS84 +pm=-360 +datum=WGS84 +no_defs")
# reproject to epsg 4326, the usual lon/lat crs
points_4326 <- points %>% st_transform(4326)
mapview::mapview(points_4326)
示例数据的头部显示旧经度(0-360)和新经度(-180 到 180):
> head(points_4326)
Simple feature collection with 6 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -166 ymin: -66 xmax: 88 ymax: -5
Geodetic CRS: WGS 84
# A tibble: 6 × 3
x y geometry
<int> <int> <POINT [°]>
1 240 -66 (-120 -66)
2 23 -66 (23 -66)
3 46 -5 (46 -5)
4 88 -10 (88 -10)
5 17 -61 (17 -61)
6 194 -13 (-166 -13)
由 reprex package 于 2022 年 4 月 19 日创建(v2.0.1)
关于r - 如何将 map 投影从太平洋中心更改为大西洋中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71929397/