OSMDATA, OSMPLOTR and OSMEXTRACT

    # osmdata - package for downloading data from OSM into R
    # it uses the overpass API
    # https://cran.r-project.org/web/packages/osmdata/vignettes/osmdata.html
    library(osmdata)
## Warning: package 'osmdata' was built under R version 4.0.5
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
    # Define a bounding box
    getbb('Copenhagen')
##        min      max
## x 12.41007 12.73007
## y 55.52672 55.84672
    q <- opq(bbox = c(12.413,55.636,  12.682, 55.729))

    # A detailed description of features is provided at the OSM wiki, 
    # or the osmdata function available_features()
    # "parking:condition"

    q <- add_osm_feature(q,key = "parking:condition")

    # There are two primary osmdata functions for obtaining data 
    # from a query: osmdata_sf() and osmdata_sp(), which return data 
    # in Simple Features (sf) and Spatial (sp) formats, respectively. 

    osm_sf <- osmdata_sf(q)
    osm_sf
## Object of class 'osmdata' with:
##                  $bbox : 55.636,12.413,55.729,12.682
##         $overpass_call : The call submitted to the overpass API
##                  $meta : metadata including timestamp and version numbers
##            $osm_points : 'sf' Simple Features Collection with 17 points
##             $osm_lines : NULL
##          $osm_polygons : 'sf' Simple Features Collection with 1 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : NULL
    # This return nothing when coordinates are entered as
    # $bbox : 55.636,12.413,55.729,12.682
    # in the order it is printed ...
    # but entering it like ..... 
    # c(12.413,55.636,12.682,55.729) gives success ..
    # example in the documentation results in no success.

    bb <- getbb('Copenhagen')
    q <- opq(bbox = bb)
    q <- add_osm_feature(q,key = "parking:condition")
    osm_sf <- osmdata_sf(q)
    osm_sf
## Object of class 'osmdata' with:
##                  $bbox : 55.5267243,12.4100724,55.8467243,12.7300724
##         $overpass_call : The call submitted to the overpass API
##                  $meta : metadata including timestamp and version numbers
##            $osm_points : 'sf' Simple Features Collection with 17 points
##             $osm_lines : NULL
##          $osm_polygons : 'sf' Simple Features Collection with 1 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : NULL
    str(osm_sf) 
## List of 8
##  $ bbox             : chr "55.5267243,12.4100724,55.8467243,12.7300724"
##  $ overpass_call    : chr "[out:xml][timeout:25];\n(\n node  [\"parking:condition\"] (55.5267243,12.4100724,55.8467243,12.7300724);\n way "| __truncated__
##  $ meta             :List of 3
##   ..$ timestamp       : chr "[ ti 3 jul 2021 17:47:58 ]"
##   ..$ OSM_version     : chr "0.6"
##   ..$ overpass_version: chr "Overpass API 0.7.56.8 7d656e78"
##  $ osm_points       :Classes 'sf' and 'data.frame':  17 obs. of  5 variables:
##   ..$ osm_id  : chr [1:17] "25286909" "930120306" "1602036112" "1602036119" ...
##   ..$ barrier : chr [1:17] "gate" NA NA NA ...
##   ..$ crossing: chr [1:17] NA NA NA NA ...
##   ..$ highway : chr [1:17] NA NA NA NA ...
##   ..$ geometry:List of 17
##   .. ..$ 25286909  : 'XY' num [1:2] 12.5 55.7
##   .. ..$ 930120306 : 'XY' num [1:2] 12.5 55.7
##   .. ..$ 1602036112: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 1602036119: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 3353617280: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 3353617281: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 3353617283: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 3353617284: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 3605573591: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 3734933571: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 5308847828: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 5308847829: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 5308847830: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 5308847831: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 7798842058: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 7798842060: 'XY' num [1:2] 12.5 55.7
##   .. ..$ 7798842061: 'XY' num [1:2] 12.5 55.7
##   .. ..- attr(*, "n_empty")= int 0
##   .. ..- attr(*, "class")= chr [1:2] "sfc_POINT" "sfc"
##   .. ..- attr(*, "precision")= num 0
##   .. ..- attr(*, "bbox")= 'bbox' Named num [1:4] 12.5 55.7 12.5 55.7
##   .. .. ..- attr(*, "names")= chr [1:4] "xmin" "ymin" "xmax" "ymax"
##   .. ..- attr(*, "crs")=List of 2
##   .. .. ..$ input: chr "EPSG:4326"
##   .. .. ..$ wkt  : chr "GEOGCRS[\"WGS 84\",\n    DATUM[\"World Geodetic System 1984\",\n        ELLIPSOID[\"WGS 84\",6378137,298.257223"| __truncated__
##   .. .. ..- attr(*, "class")= chr "crs"
##   ..- attr(*, "sf_column")= chr "geometry"
##   ..- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA
##   .. ..- attr(*, "names")= chr [1:4] "osm_id" "barrier" "crossing" "highway"
##  $ osm_lines        : NULL
##  $ osm_polygons     :Classes 'sf' and 'data.frame':  1 obs. of  10 variables:
##   ..$ osm_id           : chr "79699827"
##   ..$ name             : chr "Frederiksberg Runddel"
##   ..$ area             : chr "yes"
##   ..$ highway          : chr "pedestrian"
##   ..$ motor_vehicle    : chr "yes"
##   ..$ oneway           : chr "no"
##   ..$ parking.condition: chr "no_stopping"
##   ..$ surface          : chr "paving_stones"
##   ..$ wikidata         : chr "Q5499325"
##   ..$ geometry         :List of 1
##   .. ..$ 79699827:List of 1
##   .. .. ..$ : num [1:18, 1:2] 12.5 12.5 12.5 12.5 12.5 ...
##   .. .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. .. ..$ : chr [1:18] "3353617283" "3353617284" "1602036119" "1602036112" ...
##   .. .. .. .. ..$ : chr [1:2] "lon" "lat"
##   .. .. ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
##   .. ..- attr(*, "n_empty")= int 0
##   .. ..- attr(*, "class")= chr [1:2] "sfc_POLYGON" "sfc"
##   .. ..- attr(*, "precision")= num 0
##   .. ..- attr(*, "bbox")= 'bbox' Named num [1:4] 12.5 55.7 12.5 55.7
##   .. .. ..- attr(*, "names")= chr [1:4] "xmin" "ymin" "xmax" "ymax"
##   .. ..- attr(*, "crs")=List of 2
##   .. .. ..$ input: chr "EPSG:4326"
##   .. .. ..$ wkt  : chr "GEOGCRS[\"WGS 84\",\n    DATUM[\"World Geodetic System 1984\",\n        ELLIPSOID[\"WGS 84\",6378137,298.257223"| __truncated__
##   .. .. ..- attr(*, "class")= chr "crs"
##   ..- attr(*, "sf_column")= chr "geometry"
##   ..- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA
##   .. ..- attr(*, "names")= chr [1:9] "osm_id" "name" "area" "highway" ...
##  $ osm_multilines   : NULL
##  $ osm_multipolygons: NULL
##  - attr(*, "class")= chr [1:3] "list" "osmdata" "osmdata_sf"
    osm_sf$osm_points
##                osm_id barrier        crossing  highway           geometry
## 25286909     25286909    gate            <NA>     <NA> 12.53147, 55.67484
## 930120306   930120306    <NA>            <NA>     <NA> 12.53142, 55.67461
## 1602036112 1602036112    <NA>            <NA>     <NA> 12.53150, 55.67495
## 1602036119 1602036119    <NA>            <NA>     <NA> 12.53154, 55.67505
## 3353617280 3353617280    <NA>            <NA>     <NA> 12.53211, 55.67452
## 3353617281 3353617281    <NA>            <NA>     <NA> 12.53140, 55.67463
## 3353617283 3353617283    <NA>            <NA>     <NA> 12.53225, 55.67500
## 3353617284 3353617284    <NA>            <NA>     <NA> 12.53154, 55.67506
## 3605573591 3605573591    <NA>            <NA>     <NA> 12.53229, 55.67476
## 3734933571 3734933571    <NA>            <NA>     <NA> 12.53144, 55.67474
## 5308847828 5308847828    <NA>            <NA>     <NA> 12.53233, 55.67494
## 5308847829 5308847829    <NA>            <NA>     <NA> 12.53235, 55.67499
## 5308847830 5308847830    <NA>            <NA>     <NA> 12.53224, 55.67459
## 5308847831 5308847831    <NA> traffic_signals crossing 12.53223, 55.67453
## 7798842058 7798842058    <NA> traffic_signals crossing 12.53234, 55.67497
## 7798842060 7798842060    <NA>            <NA>     <NA> 12.53143, 55.67459
## 7798842061 7798842061    <NA>            <NA>     <NA> 12.53222, 55.67451
    osm_sf$osm_polygons
##            osm_id                  name area    highway motor_vehicle oneway
## 79699827 79699827 Frederiksberg Runddel  yes pedestrian           yes     no
##          parking.condition       surface wikidata
## 79699827       no_stopping paving_stones Q5499325
##                                                                                                                                                                                                                                                                                                                                                                        geometry
## 79699827 12.53225, 12.53154, 12.53154, 12.53150, 12.53147, 12.53144, 12.53140, 12.53142, 12.53143, 12.53211, 12.53222, 12.53223, 12.53224, 12.53229, 12.53233, 12.53234, 12.53235, 12.53225, 55.67500, 55.67506, 55.67505, 55.67495, 55.67484, 55.67474, 55.67463, 55.67461, 55.67459, 55.67452, 55.67451, 55.67453, 55.67459, 55.67476, 55.67494, 55.67497, 55.67499, 55.67500
    # Using the bbox from getbb('Copenhagen') it works ....
    # But the data you get is absolutely not useless....




    # osmplotr - a package for plotting maps based on OSM
    # https://github.com/ropensci/osmplotr
  library(osmplotr)
## Warning: package 'osmplotr' was built under R version 4.0.5
## Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
    # Make the bbox
    bb <- get_bbox(c(12.413,55.636,  12.682, 55.729))
    dat_B <- extract_osm_objects(key = "building", bbox = bb)
## Issuing query to Overpass API ...
## Rate limit: 0
## Query complete!
## converting OSM data to sf format
    dat_H <- extract_osm_objects (key = "highway", bbox = bb)
## Issuing query to Overpass API ...
## Rate limit: 0
## Query complete!
## converting OSM data to sf format
    dat_P <- extract_osm_objects (key = "park", bbox = bb)
## Issuing query to Overpass API ...
## Rate limit: 0
## Query complete!
## converting OSM data to sf format
    dat_G <- extract_osm_objects (key = "landuse", value = "grass", bbox = bb)
## Issuing query to Overpass API ...
## Rate limit: 0
## Query complete!
## converting OSM data to sf format
    map <- osm_basemap(bbox = bb, bg = "gray20")
    map <- add_osm_objects(map, dat_B, col = "gray40")
    map <- add_osm_objects(map, dat_H, col = "gray80")
    map <- add_osm_objects(map, dat_P, col = "darkseagreen")
    map <- add_osm_objects(map, dat_G, col = "darkseagreen1")
    print_osm_map(map)


    # osmextract - is a package for getting large scale OSM datasets
    # into R
    # https://github.com/ropensci/osmextract
    # a .pbf file is downloaded and converted to .gpkg.
    # The osmextract only returns sf objects.
    library(osmextract)
## Warning: package 'osmextract' was built under R version 4.0.5
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright.
## Check the package website, https://docs.ropensci.org/osmextract/, for more details.
  # Im not gonna provide example .... see the github page