r - 如何将 map 投影从太平洋中心更改为大西洋中心?

标签 r gis raster r-sf ncdf4

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/

相关文章:

gis - 在传单中,如何计算两个 LatLng 对象之间的像素距离?

performance - 填充多边形 : Performance of Winding Rule vs Even Odd Rule

r - 如何识别跨列的第一次和最后一次出现并记录位置?

css - 如何更改在 R shiny 中动态创建的文本框的背景颜色?

r - 在 ubuntu 16.04 上安装 rgdal 的麻烦

python - 使用 Numpy 转换为 Web 墨卡托

database - 计算邮政编码之间的距离...和用户。

带有离散色标的光栅图,用于负值和正值 R

r - 如何使用移动窗口迭代 R 中的裁剪栅格?

java - 在 RHEL 6 上安装 R R-java-devel 需要 java-devel