Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active July 4, 2022 01:08
Show Gist options
  • Save mdsumner/0bc3945355b38cfbadcea45a85bbf213 to your computer and use it in GitHub Desktop.
Save mdsumner/0bc3945355b38cfbadcea45a85bbf213 to your computer and use it in GitHub Desktop.

image

https://twitter.com/mdsumner/status/1543571104488636416

#install.packages("vapour")
#remotes::install_github("hypertidy/vaster")


topos <- readr::read_csv("https://raw.githubusercontent.com/hypertidy/topography/master/inst/extdata/topos.csv")
vrts <- topos |> dplyr::filter(grepl(".*opentopography.*vrt$", file)) 
show_tiling <- function(x, name = NULL, dimension = NULL, local = FALSE) {
  ex <- vaster:::extent_vrt(x)
  op <- par(xaxs = "i", yaxs = "i", mar = c(0, 0, 2, 0))
  if (local)  {
    plot(NA, xlim = range(ex[,1:2]), ylim = range(ex[,3:4]), xlab = "", ylab = "", axes = FALSE)
  } else {
    plot(NA, xlim = c(-180, 180), ylim = c(-90, 90), xlab = "", ylab = "", axes = FALSE)
  }
  maps::map(add = TRUE)
#  plot(range(ex[,1:2]), range(ex[,3:4]))
  rect(ex[,1], ex[,3], ex[,2], ex[,4], border = scales::alpha("firebrick",0.7))
  par(op)
  #browser()
  title(sprintf("%s %ix%i, %i tiles", name, dimension[1], dimension[2], nrow(ex)), line = 2, cex = 1.3)
  
  invisible(ex)
}


png(width = 850 * 2, height = 460 * 2)
par(mfrow = n2mfrow(nrow(vrts)))

for (i in seq_len(nrow(vrts))) {
  info <- vapour::vapour_raster_info(vrts$file[i])
show_tiling(gsub("/vsicurl/", "", vrts$file[i]), vrts$name[i], info$dimXY, local = F)
print(i)
}
dev.off()


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