## -----------------------------------------------------------------------------
knitr::opts_chunk$set(out.width = "100%")

## -----------------------------------------------------------------------------
library(planisphere)
library(sf)
world <- st_read(
  system.file("gpkg/land.gpkg", package = "planisphere"),
  quiet = TRUE
)

## -----------------------------------------------------------------------------
planisphere::gallery(projections = c("ConicEqualArea","Eckert3", "Hill","Loximuthal"), title = FALSE, verbose = FALSE)

## -----------------------------------------------------------------------------
op <- par(mfrow = c(1, 3), mar = c(1, 1, 2, 1))
map1 <- planisphere::project(x = world, proj = "NaturalEarth1", graticule = c(30,30), additional_layers = TRUE)
plot(sf::st_geometry(map1$sphere), main = "Pseudo", col = "#222222")
plot(sf::st_geometry(map1$graticule), col = "#D0D0D0", add= TRUE)
map2 <- planisphere::project(x = world, proj = "InterruptedHomolosine", graticule = c(30,30), additional_layers = TRUE)
plot(sf::st_geometry(map2$sphere), main = "Interrupted", col = "#222222")
plot(sf::st_geometry(map2$graticule), col = "#D0D0D0", add= TRUE)
map3 <- planisphere::project(x = world, proj = "Dodecahedral", graticule = c(30,30), additional_layers = TRUE)
plot(sf::st_geometry(map3$sphere), main = "Polyhedral", col = "#222222")
plot(sf::st_geometry(map3$graticule), col = "#D0D0D0", add= TRUE)
par(op)

## -----------------------------------------------------------------------------
planisphere::registry() |> planisphere::gallery(ncol = 6)

## -----------------------------------------------------------------------------
# library(sf)
# world <- st_read(
#   system.file("gpkg/land.gpkg", package = "planisphere"),
#   quiet = TRUE
# )

## -----------------------------------------------------------------------------
spilhaus <- planisphere::project(world, proj = "Spilhaus",
                                 additional_layers = TRUE)

## -----------------------------------------------------------------------------
planisphere::display(spilhaus,  title = "Spilhaus")

## -----------------------------------------------------------------------------
peirceN <- planisphere::project(
                            x = world,
                            proj = "PeirceQuincuncial",
                            rotate = c(-25, -90),
                            additional_layers = TRUE
                            )

peirceS <- planisphere::project(
                            x = world,
                            proj = "PeirceQuincuncial",
                            rotate = c(-25, 90, 180),
                            additional_layers = TRUE
                            )

## -----------------------------------------------------------------------------
op <- par(mfrow = c(1, 2), mar = c(0, 0, 0, 0))
planisphere::display(peirceN, title = "Peirce (North)")
planisphere::display(peirceS, title = "Peirce (South)")
par(op)

## -----------------------------------------------------------------------------
peters <- planisphere::project(
                            x = world,
                            proj = "CylindricalEqualArea",
                            parallel = 45,
                            rotate = c(167, 180),
                            additional_layers = TRUE
                            )

## -----------------------------------------------------------------------------
planisphere::display(peters, title = "Upside down Gall-Peters")

## -----------------------------------------------------------------------------
polar <- planisphere::project(
                            x = world,
                            proj = "geoAzimuthalEquidistant",
                            clipAngle = 150,
                            rotate = c(0, -90),
                            additional_layers = TRUE
                            )

## -----------------------------------------------------------------------------
planisphere::display(polar, title = "Polar projection")

## -----------------------------------------------------------------------------
hao <- planisphere::project(
                            x = world,
                            proj = "geoHufnagel",
                            a = 0.8,
                            b = 0.35,
                            psiMax = 50,
                            ratio = 1.6,
                            angle = 90,
                            rotate = c(110, -200, 90),
                            additional_layers = TRUE
                            )

## -----------------------------------------------------------------------------
planisphere::display(hao, title = "≈ Hao Xiaoguang projection")

## -----------------------------------------------------------------------------
europe <- sf::st_read("https://gisco-services.ec.europa.eu/distribution/v2/nuts/gpkg/NUTS_RG_20M_2024_4326_LEVL_0.gpkg", quiet = TRUE) |>
 sf::st_crop(xmin=-10, xmax=45, ymin=25, ymax=72)
france <- europe[europe$ISO3_CODE == "FRA",]


## -----------------------------------------------------------------------------
laea = planisphere::project(europe, 
                            proj = "AzimuthalEqualArea", 
                            rotate = c(-10, -52)
                            )

## -----------------------------------------------------------------------------
lambert93 <- planisphere::project(france, 
                                 proj = "ConicConformal", 
                                 rotate = c(-3,0), 
                                 center = c(0, 46.5),
                                 parallels = c(44,49),
                                 clipExtent =  list(c(0, 0), c(1000, 1000))
                                 )

## -----------------------------------------------------------------------------
op <- par(mfrow = c(1, 2), mar = c(0, 0, 0, 0))
planisphere::display(laea, title = "≈ LAEA")
planisphere::display(lambert93, title = "≈ Lambert 93")
par(op)

