Get Map Layers from 'OpenStreetMap'

The 'OpenStreetMap' database provides a wide range of highly detailed geographic layers on a global scale. To obtain synthetic information for cartographic purposes, layers must be selected, simplified, merged, or modified. 'maposm' downloads 'OpenStreetMap' extracts and performs these operations to create a set of composite layers of urban areas, buildings, green spaces, main roads, secondary roads, railways, and water bodies.


maposm

maposm statusbadge code coverage:84%

The OpenStreetMap database provides a wide range of highly detailed geographic layers on a global scale. To obtain synthetic information for cartographic purposes, layers must be selected, simplified, merged, or modified.
maposm downloads OpenStreetMap extracts and performs these operations to create a set of composite layers of urban areas, buildings, green spaces, main roads, secondary roads, railways, and water bodies.

Installation

You can install maposm from the r-universe.

install.packages('maposm', repos = c('https://riatelab.r-universe.dev', 'https://cloud.r-project.org'))

Demo

om_get() is used to download, merge and simplify the geographic layers.
om_map() is used to map the layers.

library(maposm)
#> Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright.
#> Maps based on OpenStreetMap data should cite "© OpenStreetMap contributors" as the data source.
f2f = om_get(x = c(-61.070, 14.605), r = 600)
#> # Download the OpenStreetMap file
#> The input place and the radius matched the sample dataset.
#> Skip download and data extraction.
#> 
#> # Create map layers
#> - green spaces
#> - buildings
#> - urban areas
#> - roads
#> - streets
#> - railways
#> - water bodies
#> 
#> Done!
om_map(x = f2f, title = "Fort-de-France, Martinique", theme = "light")

Several themes are available to map the layers (“light”, “dark”, “grey” and “pizza”).

om_map(x = f2f, title = "Fort-de-France, Martinique", theme = "grey")

You can also use your prefered library to map the layers.

library(mapsf)
mf_map(f2f$zone, col = "#f2efe9", border = NA, add = FALSE)
mf_map(f2f$urban, col = "#e0dfdf", border = "#e0dfdf", lwd = .5, add = TRUE)
mf_map(f2f$green, col = "#c8facc", border = "#c8facc", lwd = .5, add = TRUE)
mf_map(f2f$water, col = "#aad3df", border = "#aad3df", lwd = .5, add = TRUE)
mf_map(f2f$railway, col = "grey50", lty = 2, lwd = .2, add = TRUE)
mf_map(f2f$street, col = "white", border = "white", lwd = .5, add = TRUE)
mf_map(f2f$road, col = "#f7fabf", border = "#f7fabf", lwd = .5, add = TRUE)
mf_map(f2f$building, col = "#d9d0c9", border = "#c6bab1", lwd = .5, add = TRUE)
mf_map(f2f$zone, col = NA, border = "#c6bab1", lwd = 4, add = TRUE)
mf_credits(txt = "\ua9 OpenStreetMap contributors")
mf_scale(size = 100, scale_units = "m")
mf_title("Fort-de-France, Martinique")

om_write() can be used to write the layers to a geopackage file.
om_read() can be used to read these geopackages.

# save
om_write(x = f2f, filename = "f2f.gpkg")
# import
om_read(x = "f2f.gpkg")

Alternatives

  • osmdata to access to OSM data through the overpass API
  • osmplotr from the author of osmdata
  • osmextract for large extracts from OSM
  • prettymaps is a full featured Python library
  • mapBliss to plot flight paths and road trips on OSM map
  • maptiles to download (raster) OSM map tiles
  • cartographr to plot OSM layers using ggplot2
  • rcityviews to map cities, it has a shiny interface

Community Guidelines

One can contribute to the package through pull requests and report issues or ask questions here. This project uses conventional commits and semantic versioning.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("maposm")

0.5.1 by Timothée Giraud, 23 days ago


https://codeberg.org/riatelab/maposm, https://riatelab.r-universe.dev/maposm


Report a bug at https://codeberg.org/riatelab/maposm/issues


Browse source code at https://github.com/cran/maposm


Authors: Timothée Giraud [cre, aut] (ORCID: , Matthieu Viry [ctb] , Louis Laurian [ctb]


Documentation:   PDF Manual  


GPL-3 license


Imports sf, lwgeom, tools, mapsf, graphics, osmextract

Suggests tinytest


See at CRAN