This is an old question with some good old answers.
Here an updated, full R
solution using the packages osmdata
to fetch the OSM data and sf
to manage and save the geometry:
# install.packages("osmdata")
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
# Check the available features
osmdata::available_features() %>% head()
#> [1] "4wd only" "abandoned" "abutters" "access" "addr" "addr:city"
# In our case, we are interested in 'highway'
selected_feature = "highway"
# Check available tags for the selceted feature
osmdata::available_tags(selected_feature) %>% head()
#> [1] "bridleway" "bus_guideway" "bus_stop" "construction" "corridor"
#> [6] "crossing"
# For simplicity,we are going to download all
selected_tags = osmdata::available_tags(selected_feature)
# Create the request for Overpass API
q = osmdata::getbb ("Baranduda",
display_name_contains="Australia",
# limit=1e04,
format_out = "polygon") %>%
osmdata::opq() %>%
osmdata::add_osm_feature(selected_feature
,selected_tags)
# Download the data
o = osmdata::osmdata_sf(q)
# Street geometry can be lines (roads) and polygons (loops, roundabouts, etc.)
# We are going to merge the two type of geometry
# converting polygons to linestrings
full_street = o$osm_polygons %>%
sf::st_cast("LINESTRING", warn=FALSE) %>%
rbind(o$osm_lines)
# Save the file (here in temporary file)
output_file = tempfile(fileext=".shp")
sf::st_write(full_street, output_file)
You will get a warning when you save the data, due to the fact that field names are abbreviated for the shapefile format.
I suggest you use a more up to date format such as .gpkg
:
sf::st_write(full_street, "your-file-name.gpkg")
You can visualise the results with mapview
:
mapview::mapview(full_street)
Created on 2020-05-04 by the reprex package (v0.3.0)