sf::st_transform not honoring +lon_wrap · Issue #280 · r-spatial/sf (original) (raw)

Hello

I'm working with a number of lines that cross back and forth of 180. When working in a projection (e.g. 3571), this isn't an issue. But, if I want to add those lines to a leaflet map, I need to transform to 4326. With sp::spTransform() I've been able to pass along the +lon_wrap=180 specification and this converts the longitude coordinates to 0-360 which leaflet respects

library(sp) library(sf) library(magrittr) library(leaflet)

l <- "LINESTRING(-150.5 57.0,-160.5 57.0,-170.5 57.0,179.5 57.0,169.5 57.0,159.5 57.0)" %>% sf::st_as_sfc(crs = "+init=epsg:4326")

l_sp <- as(l,"Spatial") l_sp <- sp::spTransform(l_sp,"+proj=longlat +datum=WGS84 +lon_wrap=180") sp::proj4string(l_sp) bbox(l_sp)

m <- l_sp %>% leaflet() %>% addProviderTiles("Esri.OceanBasemap") %>% addPolylines(weight = 4, opacity = 0.35, color = 'black') m

However, when I try to accomplish the same thing with sf, the +lon_wrap appears to be ignored.

m <- l %>% sf::st_transform("+proj=longlat +datum=WGS84 +lon_wrap=180") %>% leaflet() %>% addProviderTiles("Esri.OceanBasemap") %>% addPolylines(weight = 4, opacity = 0.35, color = 'black') m

l %>% sf::st_transform("+proj=longlat +datum=WGS84 +lon_wrap=180") %>% sf::st_crs() l %>% sf::st_transform("+proj=longlat +datum=WGS84 +lon_wrap=180") %>% sf::st_bbox()

> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3

leaflet_1.1.0.9000
sp_1.2-4
sf_0.3-4

Is this a known/expected difference between sp::spTransform and sf::st_transform? Is there a different approach I should be taking?