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:
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
# Check the available features
osmdata::available_features() %>% head()
#>  "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()
#>  "bridleway" "bus_guideway" "bus_stop" "construction" "corridor"
#>  "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",
format_out = "polygon") %>%
# 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) %>%
# Save the file (here in temporary file)
output_file = tempfile(fileext=".shp")
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
You can visualise the results with
Created on 2020-05-04 by the reprex package (v0.3.0)