Skip to content

Instantly share code, notes, and snippets.

@kadyb
Last active January 7, 2023 15:40
Show Gist options
  • Save kadyb/f7071a6ab611c6994ceefe34045e33dd to your computer and use it in GitHub Desktop.
Save kadyb/f7071a6ab611c6994ceefe34045e33dd to your computer and use it in GitHub Desktop.
R script to download buildings footprints from Microsoft Bing Maps
library("sf")
library("geojsonsf")
options(timeout = 600)
url = "https://minedbuildings.blob.core.windows.net/global-buildings/dataset-links.csv"
links = read.csv(url)
# select sample data (Bangkok)
bangkok = subset(links,
Location == "Thailand" &
QuadKey %in% c(132203132, 132203133, 132203310, 132203311))
geom = character()
for (i in seq_len(nrow(bangkok))) {
fname = paste0(bangkok$QuadKey[i], ".csv.gz")
download.file(bangkok$Url[i], fname, mode = "wb")
geom_tmp = readLines(fname)
geom = c(geom, geom_tmp)
file.remove(fname)
}
rm(geom_tmp)
geom = geojson_sfc(geom) # convert geojson to sfc
write_sf(geom, "bangkok.gpkg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment