scratch for pacific-centered mapping

test <- st_as_sfc(st_bbox(c(xmin = 10, ymin = -90, xmax = 35, ymax = 90), crs = 4326))

test2 <- maps::map('world', fill = TRUE, plot = FALSE) %>%
  st_as_sf() %>%
   st_make_valid() %>%
   st_difference(test) %>%
 # st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=-150")) %>%
   st_transform('+proj=moll +lon_0=-150') %>%
   #st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=-18034090")) %>%
   plot

test2 <- maps::map('world', fill = TRUE, plot = FALSE) %>%
  st_as_sf() %>%
  st_make_valid() %>%
  st_difference(st_as_sfc(st_bbox(c(xmin = -1, ymin = -90, xmax = 25, ymax = 90), crs = 4326))
) %>%
  st_transform('+proj=moll +lon_0=180')

plot(world)
ggplot( maps::map('world2', fill = TRUE, plot = FALSE) %>%
    st_as_sf() ) +
  geom_sf(color = NA, fill = 'grey20') +
  coord_sf(crs = "+proj=ortho +lat_0=30 +lon_0=180")

  coord_sf(crs = '+proj=moll +lon_0=180', ylim = c(-7500000, 7500000))

st_make_valid()%>%
   st_simplify() %>%
   st_crop(st_bbox(c(xmin = 20, xmax = 300, ymin = -76, ymax = 76))) %>%
  st_transform('+proj=moll +lon_0=180 +ellps=WGS84 +datum=WGS84 +units=m no_defs') %>%
   plot
  #st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=1")) %>%
  ggplot() + geom_sf() + coord_sf(xlim =c(-15000000, 800))

world <- maps::map('world', fill = TRUE, plot = FALSE) %>%
  st_as_sf() #%>%
  st_transform('+proj=moll +lon_0=180 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs') %>%
  st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=90")) %>% plot


wrld <- st_as_sf(maps::map("world", fill = TRUE, plot = FALSE))
wrld_wrap <- st_wrap_dateline(wrld, options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180"),
                              quiet = TRUE)
wrld_moll <- st_transform(wrld_wrap, "+proj=moll")
plot(st_geometry(wrld_moll), col = "transparent")
plot(st_transform(sst2[,,,1], '+proj=moll'))
plot(st_transform(geop[,,,1], '+proj=moll'))

d <- rnaturalearth::ne_countries(returnclass = "sf", scale = 'small') %>%
  st_set_precision(1e7) %>%
  st_as_s2() %>%
  st_as_sf()
x1 <- st_crop(d, st_bbox(c(xmin = 0, xmax = 180, ymin = -90, ymax = 90)))
x2 <- st_crop(d, st_bbox(c(xmin = -180, xmax = -0.001, ymin = -90, ymax = 90)))

## add more groupings for whatever columns you also want to keep
x <- rbind(x1, x2)
## mollwiede on lon=180
prj <- "+proj=moll +lon_0=180 +ellps=WGS84 +datum=WGS84 +no_defs"
## fudge above means we get a seam in Antarctica and Russia ....
world <- sf::st_transform(x[1], prj)
plot(world)

world <- st_as_sf(maps::map("world", wrap = c(0,360), fill = TRUE, plot = FALSE)) %>%
  st_make_valid()# %>%
 # st_set_precision(1e7) %>%
 # st_simplify() %>%
 #st_crop(., st_bbox(c(xmin = 1, ymin = -80, xmax = 359, ymax = 80), crs = st_crs(.))) %>%
  plot


nick-gauthier/tidyEOF documentation built on July 21, 2023, 8:25 a.m.