library(sf)
library(tidyverse)
I have an sf object with
geometry type:point
projected over pacific
bbox: xmin: 0 ymin: -78 xmax: 359 ymax: 0 (WGS 84)
I want to re-project the sf object to Atlantic centered (-180,180) from pacific view (0,360). I found in sf package a function that allows to go from Atlantic to Pacific view (i.e.) st_shift_longitude(x)
. But what I want is the opposite ...
Help? Thanks
Tough to tell for sure without some hint at what the data looks like, but here's one way to do it:
I'm assuming the original
sf
object of points doesn't have a crs set, since 0-360 for longitude is unusual. The code below makes up some data points using -78-0 for latitude & 0-360 for longitude. A (somewhat unusual) crs of"+proj=longlat +ellps=WGS84 +pm=-360 +datum=WGS84 +no_defs"
is set, and then transformed to the usual 4326 for lon/lat data.Head of the sample data showing both old (0-360) longitude, and new (-180 to 180) longitude:
Created on 2022-04-19 by the reprex package (v2.0.1)