The OpenStreetMap database provides
numerous and very detailed geographic layers on a global scale. To
obtain synthetic information that can be used for cartographic purposes,
layers must be selected, simplified, merged, or modified.
The maposm package provides a set of composite layers that are built
from extractions performed with the
osmdata package (which itself
uses the Overpass
API).
The resulting layers are:
- Urban areas
- Buildings
- Green spaces
- Main roads
- Secondary roads
- Railroads
- Water bodies
You can install maposm from the r-universe.
install.packages("maposm", repos = "https://riatelab.r-universe.dev")om_get() is used to download, merge and simplify the geographic
layers.
om_map() can be 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.
castries = om_get(x = c(-60.9903, 14.0096), r = 2000)
#> Getting urban areas: 0.878 sec elapsed
#> Getting buildings: 6.82 sec elapsed
#> Getting green areas: 1.393 sec elapsed
#> Getting roads: 0.557 sec elapsed
#> Getting streets: 0.732 sec elapsed
#> Getting railways: 0.459 sec elapsed
#> Getting water bodies: 11.854 sec elapsed
om_map(x = castries, title = "Castries, Saint Lucia", theme = "light")Several themes are available to map the layers (“light”, “dark”, “grey” and “pizza”).
om_map(x = castries, title = "Castries, Saint Lucia", theme = "grey")You can also use an sf object to extract the layers and your prefered library to map the layers.
library(mapsf)
roseau = st_as_sf(data.frame(lat = 15.300, lon = -61.388),
coords = c("lon", "lat"),
crs = "EPSG:4326") |>
st_transform("EPSG:3857") |>
st_buffer(dist = 500, nQuadSegs = 2) |>
om_get(quiet = TRUE)
mf_map(roseau$zone, col = "#f2efe9", border = NA, add = FALSE)
mf_map(roseau$urban, col = "#e0dfdf", border = "#e0dfdf", lwd = .5, add = TRUE)
mf_map(roseau$green, col = "#c8facc", border = "#c8facc", lwd = .5, add = TRUE)
mf_map(roseau$water, col = "#aad3df", border = "#aad3df", lwd = .5, add = TRUE)
mf_map(roseau$railway, col = "grey50", lty = 2, lwd = .2, add = TRUE)
mf_map(roseau$road, col = "white", border = "white", lwd = .5, add = TRUE)
mf_map(roseau$street, col = "white", border = "white", lwd = .5, add = TRUE)
mf_map(roseau$building, col = "#d9d0c9", border = "#c6bab1", lwd = .5, add = TRUE)
mf_map(roseau$zone, col = NA, border = "#c6bab1", lwd = 4, add = TRUE)
mf_credits(txt = "\ua9 OpenStreetMap contributors")
mf_scale(size = 100, scale_units = "m")
mf_title("Roseau, Dominique")om_write() can be used to write the layers to a geopackage file.
om_read() can be used to read the geopackages.
# save
om_write(x = roseau, filename = "roseau.gpkg")
# import
om_read(x = "roseau.gpkg")osmdatato access to OSM data through the overpass APIosmplotrfrom the author ofosmdataosmextractfor large extracts from OSMprettymapis a full featured Python librarymapBlissto plot flight paths and road trips on OSM mapmaptilesto download (raster) OSM map tilescartographrto plot OSM layers usingggplot2rcityviewsMap a selection of cities + R shiny interface
One can contribute to the package through pull requests and report issues or ask questions here. This project uses conventional commits and semantic versioning.



