r-spatial/s2

Visualizing s2 cell covering on a globe

natemiller opened this issue · 2 comments

I am trying to teach about the use of s2 cells as coverings and having the ability to plot and visualize s2 cells of different sizes, etc. is helpful.
In the past, I have done this with the older version of the s2 and spatstat.sphere packages using variations on the code below using s2covering.

library(spatstat.sphere)
library(globe)

earth <- spatstat.sphere::s2earth()
lev5 <- spatstat.sphere::s2covering(earth, min_level = 5, max_level = 5)

globe::globeearth(eye=WG)
plot(lev5, add = TRUE)

I have looked through the documentation and tried a number of different approaches, but haven't been able to identify the correct formulation with the new s2 functions. Is this type of visualization of the s2 cells possible with the current s2 package and if so, can you point me in the right direction? Very much appreciated.

It won't be available until the next s2 release (soon!), but if you're ok with installing the development version you can do:

# remotes::install_github("r-spatial/s2")
library(s2)

antarctica <- s2_data_countries("Antarctica")
covering <- s2_covering_cell_ids(antarctica)
covering_polygons <- s2_cell_polygon(unlist(covering))

# export with tessellated edges for plotting elsewhere:
covering_polygons_flat <- s2_as_binary(covering_polygons, planar = TRUE)

# or plot using s2_plot
s2_plot(covering_polygons)
s2_plot(antarctica, add = T)

Created on 2022-06-24 by the reprex package (v2.0.1)

I hope that helps!

Works great! Thank you for a great package.