library(sf)
Linking to GEOS 3.9.2, GDAL 3.3.3, PROJ 8.2.1; sf_use_s2() is TRUE
library(tmap)
library(spData)
data("world")
May 5, 2018
Linking to GEOS 3.9.2, GDAL 3.3.3, PROJ 8.2.1; sf_use_s2() is TRUE
world_sfc4 = world_sfc + c(180, 0)
world_sfc4 = lwgeom::st_make_valid(world_sfc4)
world_sfc4 = world_sfc4 %>%
st_set_crs(4326) %>%
st_segmentize(1000000)
x = world_sfc4 %>%
st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180"), quiet = TRUE) %>%
st_set_precision(1000) %>%
st_union(by_feature = TRUE)
tm_shape(x) +
tm_polygons()
world_sfc22 = st_segmentize(world_sfc, 1000)
world_sfc4 = world_sfc22 + c(45, 0)
x = world_sfc4 %>%
st_set_crs(4326) %>%
lwgeom::st_make_valid() %>%
st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=45"), quiet = TRUE) %>%
st_set_precision(1000) %>%
st_union(by_feature = TRUE)
tm_shape(x) +
tm_polygons()
recentre = function(x,
clon = NULL,
...,
tryfix = TRUE) {
if (is.null(clon))
return(x)
if (!st_is_longlat(x))
stop("recentring not appropriate for non longlat data")
## save the crs while we do our munging
crs = st_crs(x)
x = st_set_crs(x, NA)
## try to fix problematic geometry
if (tryfix) {
if (all(grepl("POLYGON", st_geometry_type(x))))
x = suppressWarnings(st_buffer(sf::st_as_sf(x), 0))
x =
st_wrap_dateline(x, options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180"))
}
wbox =
st_bbox(c(
xmin = -180,
ymin = -90,
xmax = (clon) %% 360 - 180,
ymax = 90
))
west = suppressWarnings(st_crop(x, wbox))
west = st_set_geometry(west, st_geometry(west) + c(360, 0))
east =
suppressWarnings(st_crop(x, st_bbox(
c(
xmin = (clon) %% 360 - 180,
xmax = 180,
ymin = -90,
ymax = 90
)
)))
xx = rbind(west, east)
## ensure geometries are of consistent type
xx = sf::st_cast(xx)
bb = st_bbox(xx)
## hmmm
# if (bb["xmax"] > 180 && !grepl("\\+over", crs) && !grepl("init", crs)) {
# crs = sprintf("%s +over", crs)
# }
st_set_crs(xx, crs)
}
world2 = rmapshaper::ms_simplify(world, keep = 0.99)
all(st_is_valid(world2))
world2 = lwgeom::st_make_valid(world2)
library(dplyr)
rsx = recentre(world2, clon = -152) %>%
group_by(name_long) %>%
summarize()
@online{nowosad2018,
author = {Nowosad, Jakub},
title = {World Map Reimagined},
date = {2018-05-05},
url = {https://jakubnowosad.com/posts/drafts/XXXX-XX-XX-world-map-reimagined.html},
langid = {en}
}