README.md

osmxml

DOI

osmxml is an R package useful to download, read, prepare and (rudimentarily) visualise OpenStreetMap (OSM) XML files like the map.osm file you would get from the OSM website’s “Export” page.

This package might not be what you’re after: please see below the section “Other OSM-related R packages” to find more powerful tools.

Installation

You can install the development version of osmexport from GitHub with:

# install.packages("devtools")
devtools::install_github("stragu/osmxml")

Available functions

The osm class

The osm S3 class – very much subject to changing in name and properties – has print() and plot() methods. It is made of sf (“simple features”) spatial objects.

Example

The functions available are designed to be pipeable. For example, to download and read the area around Te Kura Tatauranga, Waipapa Taumata Rau:

library(osmxml)
#> All data, downloaded or included as an example, is © OpenStreetMap contributors, and the conditions of its reuse are defined by the ODbL licence.
#> Find out more on the OSM website: https://www.openstreetmap.org/copyright
TKT <- c(174.76598, -36.85440, 174.77019, -36.85129) |>
  ox_download() |>
  ox_read()
#> Using cached .osm file with same bbox, which was last modified on 2022-08-06 00:09:17
# see what the object contains
TKT
#> OSM data object made of 5 simple feature collections: points, lines, multilinestrings, multipolygons, other_relations
#> The corresponding sf geometry types are:
#>             points              lines   multilinestrings      multipolygons 
#>              POINT         LINESTRING    MULTILINESTRING       MULTIPOLYGON 
#>    other_relations 
#> GEOMETRYCOLLECTION

We can now use the default plot method to have a glimpse at the data:

plot(TKT)

Because the parts of the object are of class sf, they can be processed with sf and well as dplyr functions:

library(dplyr)
library(sf)
# most common "building" values in polygons
TKT$multipolygons |>
  st_drop_geometry() |>         # remove geometry column
  filter(!is.na(building)) |>   # only keep buildings
  count(building, sort = TRUE)  # most commons values at the top
#>      building  n
#> 1  university 31
#> 2         yes  6
#> 3        roof  5
#> 4  apartments  2
#> 5      church  1
#> 6       civic  1
#> 7     garages  1
#> 8      gazebo  1
#> 9      retail  1
#> 10      ruins  1

Contributions and feedback

Contributions are welcome and appreciated. You can contribute to this package by:

Note that all contributions to the codebase will be released under the GPL, and submitting your contribution to this repository is an implicit agreement.

We expect contributors to respect UQRUG’s Code of Conduct.

If a conversation or comment does not belong in a public issue report, please contact the maintainer listed in the package description.

Data licence

OSM data included in this package (in the ./inst directory) and downloaded with the ox_download() function is © OpenStreetMap contributors, and the conditions of its reuse are defined by the ODbL licence. You likely need to include this information on anything derived from it. Find out more on the OSM website.

Other OSM-related R packages

There are many other OSM-related R packages that might be more suitable for what you are hoping to achieve. Notable packages available on CRAN are:

Transport-specific packages:

To acquire basemaps:

Other interactive visualisation packages automatically fetch rendered OSM data as basemaps, like leaflet and tmap.



stragu/osmexport documentation built on Aug. 7, 2022, 12:07 a.m.