I'm trying to create a polygon that has longitudinal limits as 150, -170, i.e. crosses the 180 meridian dateline.
I've tried:
x = c(-170, -170, 150, 150) #long limits
y = c(-25,-57,-57,-25) #lat limits
polygon = cbind(x, y) %>%
st_linestring() %>%
st_cast("POLYGON") %>%
st_wrap_dateline(options = c("WRAPDATELINE=YES")) %>% #thought this line could solve it
st_sfc(crs = 4326, check_ring_dir = TRUE) %>%
st_sf()
That is not solving the problem, even if I delete the 'st_cast' cast line or use 'MULTIPOLYGONS' instead of 'POLYGONS' in there. I've also created one polygon with positive longitudes and another for the negative ones, and then combined them, but that's not working well (R runs it, but I get nothing when plotting the object with combined polygons).
I would greatly appreciate it if you could provide your ideas on this :)
I think you can do it simply passing the coordinates, but this should be combined also with the right coordinate reference system:
POLYGON
from a bounding box quickly, as far as you assign it the class of a bounding boxbox
and after that usest_as_sfc()
.sf_use_s2(TRUE)
, available onsf >= 1.0.0
.See here how to do it:
If you want to plot it you must use a suitable projection for your coordinates. In this case I use an Ortographic projection centered in
c(-160, -40)
:If you want to have a
MULTIPOLYGON
instead aPOLYGON
Use
st_shift_longitude()
+st_wrap_dateline()
.