Skip to content

Instantly share code, notes, and snippets.

@kadyb
Last active February 4, 2023 21:09
Show Gist options
  • Save kadyb/1961dae1ac0e020b02607454c1ae187e to your computer and use it in GitHub Desktop.
Save kadyb/1961dae1ac0e020b02607454c1ae187e to your computer and use it in GitHub Desktop.
Extract national roads from Microsoft's dataset (Bing Maps) in R
library("sf")
library("readr")
library("geojsonsf")
## download all roads for Europe
data = "https://usaminedroads.blob.core.windows.net/road-detections/Europe-Full.zip"
options(timeout = 6000)
download.file(data, "Europe-Full.zip")
unzip("Europe-Full.zip")
## read data in chunks (and select only in Czech Republic)
f = function(x, pos) subset(x, country == "CZE")
df = read_tsv_chunked("Europe-Full.tsv", DataFrameCallback$new(f),
col_names = c("country", "geom"),
chunk_size = 100000, col_types = "fc")
geom = geojson_sfc(df$geom)
write_sf(geom, "CZE.gpkg") # save as geopackage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment