-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sf::st_transform not honoring +lon_wrap #280
Comments
Yes: > st_wrap_dateline(st_sfc(st_linestring(rbind(c(-179,0),c(179,0))), crs = 4326))
Geometry set for 1 feature
geometry type: MULTILINESTRING
dimension: XY
bbox: xmin: -180 ymin: 0 xmax: 180 ymax: 0
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
MULTILINESTRING((-179 0, -180 0), (180 0, 179 0)) This option is also in line with the geojson rfc, which prescribes that longitudes should be in [-180,180], but geometries crossing the antimeridian should be cut there (see par. 3.1.9). |
Thanks for the explanation. I built the latest l1 <- st_sfc(st_linestring(rbind(c(-179,0),
c(179,0))), crs = 4326) %>%
sf::st_wrap_dateline()
l2 <- st_sfc(st_linestring(rbind(c(-150.5,57.0),
c(159.5,57.0))),crs=4326) %>%
sf::st_wrap_dateline() If we examine
I also tried to replicate my previous example in
|
There is another parameter, set by l2 %>% st_wrap_dateline(c("WRAPDATELINE=YES", "DATELINEOFFSET=60")) it has by default a value 10, and seems to determine the range around the dateline (default: +/- 5 degrees) between which geometries to split are expected to lie. The thing is, if you continue this experiment, at some stage the shortest line will no longer cross the dateline.
|
Please report back whether this is still an open issue to you, or whether we can close. |
I think from an I still, however, can't find a solution for adding an |
See the example in library(sf)
library(maps)
w = st_as_sf(map('world', plot = FALSE, fill = TRUE))
w2 = (st_geometry(w) + c(360,90)) %% c(360) - c(0,90)
plot(w2, axes = TRUE) (which doesn't look nice, but does the -180,180 -> 0,360, afaics) |
Kia ora I'm working with a sf object polygon that crosses the 180 line. I used to be able to run processes, such as intersecting with another polygon also straddling the 180 line but converting to sp:: object and then using sp::spTransform("+proj=longlat +datum=WGS84 +lon_wrap=180"). However, I've just discovered that if I re-run sp::spTransform("+proj=longlat +datum=WGS84 +lon_wrap=180") it no longer seems to transform that the extent from being described in terms of -180W to 180 E to 0 - 360. I thought it might have something to do with the fact that I was no longer using the same version of sp:: So I rolled back from 2.1-4 to 1.6-1 and then 2.0-0. However, this rolling back didn't seem to resolve the issue. I then noticed a note that sp package is now running under evolution status 2 (evolution status 2 uses the sf package instead of rgdal). Which lead me (via Google) to sp evolution status: examples of migration from retiring packages. I might be missing something but this report seems to suggest that versions prior to 2.0-0 should still be using rgda which directly calls routines in proj.4.
In sum, can you please clarify why converting to sp and then spTransforming using lon_wrap=180 not longer seems to work. And why rolling back to an earlier version (<2.0-0) doesn't seem to get it working? Given my old trick no longer seems to be working I'd really appreciate any help with how to run processes on polygons that straddle the 180 line? E.g. what can I do to st_intersection(nz_grid_300, nz_bbox)??? Thanks heaps in advance, John |
I don't think
the first bounding box you see is reported by |
Thanks Edzer Good to clarify that the two different bounding boxes come from different routes. Given your suggestion that this issue could have something to do with 'dggridR::', I have tried with polygons that were not created using 'dggridR::' and I still seem to run into the issue... If I use the 'nz_bbox' polygon from above I still don't seem to be able to process this polygon in a way that respects the 180 line. For example, if I use a negative buffer to shrink the polygon, it returns a polygon that wraps the wrong way wrong the 180 line. So I'm not sure that this is just a 'dggridR' issue? I'm interested whether it is still possible to even use the ' as("Spatial") %>%
|
p.s. just discovered that ' st_shift_longitude()' seems to work and provides a nicer way of keeping the objects as sf (rather than having to convert to sp). |
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 respectsHowever, when I try to accomplish the same thing with
sf
, the+lon_wrap
appears to be ignored.Is this a known/expected difference between
sp::spTransform
andsf::st_transform
? Is there a different approach I should be taking?The text was updated successfully, but these errors were encountered: