ropensci / osmextract

Download and import OpenStreetMap data from Geofabrik and other providers
https://docs.ropensci.org/osmextract
GNU General Public License v3.0
168 stars 12 forks source link

Benchmarks and documentation on when to use geofabrik #42

Open Robinlovelace opened 4 years ago

Robinlovelace commented 4 years ago

It's clear that there are many cases when bulk extract download is not the best way to get OSM data. Would be useful to users to know when osmdata is quicker.

Example: you want cycleways in Louvain-la-Neuve in Belgium. With geofabrik:

# remotes::install_github("itsleeds/geofabrik")
library(geofabrik)
lvn_centroid = tmaptools::geocode_OSM("louvain-la-neuve", as.sf = T)
system.time({ # around 2 seconds
  lvn = get_geofabrik(lvn_centroid)
  })
#> although coordinates are longitude/latitude, st_contains assumes that they are planar
#> The place is within these geofabrik zones: Europe, Belgium
#> Selecting the smallest: Belgium
#> Downloading http://download.geofabrik.de/europe/belgium-latest.osm.pbf to 
#> ~/h/data/osm/Belgium.osm.pbf
#> Old attributes: attributes=name,highway,waterway,aerialway,barrier,man_made
#> New attributes: attributes=name,highway,waterway,aerialway,barrier,man_made,maxspeed,oneway,building,surface,landuse,natural,start_date,wall,service,lanes,layer,tracktype,bridge,foot,bicycle,lit,railway,footway
#> Using ini file that can can be edited with file.edit(/tmp/RtmprktWUQ/ini_new.ini)
#>    user  system elapsed 
#>  72.514  18.150 269.507
plot(louvain_highway)

Created on 2020-02-06 by the reprex package (v0.3.0)

Robinlovelace commented 4 years ago

Equivalent code in osmdata takes 2 seconds!

library(osmdata)
library(sf)
system.time({ # around 2 seconds
  n = "louvain-la-neuve"
  v = "primary|secondary|cycleway"
  louvain = opq(n) %>% 
  add_osm_feature("highway", v,
    value_exact = F) %>%
  osmdata_sf()
  })
#>    user  system elapsed 
#>   0.125   0.020   1.814
louvain_highway = louvain$osm_lines
plot(louvain_highway)