Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active August 24, 2025 22:43
Show Gist options
  • Save mdsumner/37e8a5ef32e563819794c9bf3bb4a801 to your computer and use it in GitHub Desktop.
Save mdsumner/37e8a5ef32e563819794c9bf3bb4a801 to your computer and use it in GitHub Desktop.
cnts <- rnaturalearth::ne_countries()
n <- nrow(cnts)
sf::sf_use_s2(FALSE)
pfun <-function(x) {
  x <- x[1, ]
  #expecting a sf cnt
  op <- options(warn = -1)
  on.exit(options(op))
  cnt <- sf::st_coordinates(  sf::st_centroid(x))
  prj <- sprintf("+proj=laea +lon_0=%f +lat_0=%f", cnt[1], cnt[2])
  sf::st_transform(x, prj)
}

plot(pfun(cnts[23, ])[0])
par(mfrow =n2mfrow(nrow(cnts)), mar = rep(0, 4))
for (i in sample(n)) {
  plot(sf::st_geometry(pfun(cnts[i, ])[0]))
  
}

@mdsumner
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment