get_openstreetmap: Get an OpenStreetMap

View source: R/get_openstreetmap.R

get_openstreetmapR Documentation

Get an OpenStreetMap


get_openstreetmap() accesses a tile server for OpenStreetMap and downloads/formats a map image. This is simply a wrapper for the web-based version at If you don't know how to get the map you want, go there, navigate to the map extent that you want, click the export tab at the top of the page, and copy the information into this function.


  bbox = c(left = -95.80204, bottom = 29.38048, right = -94.92313, top = 30.14344),
  scale = 606250,
  format = c("png", "jpeg", "svg", "pdf", "ps"),
  messaging = FALSE,
  urlonly = FALSE,
  filename = NULL,
  color = c("color", "bw"),



a bounding box in the format c(lowerleftlon, lowerleftlat, upperrightlon, upperrightlat)


scale parameter, see smaller scales provide a finer degree of detail, where larger scales produce more coarse detail. The scale argument is a tricky number to correctly specify. In most cases, if you get an error when downloading an openstreetmap the error is attributable to an improper scale specification. OSM_scale_lookup() can help; but the best way to get in the correct range is to go to, navigate to the map of interest, click export at the top of the page, click 'map image' and then copy down the scale listed.


character string providing image format - png, jpeg, svg, pdf, and ps formats


turn messaging on/off


return url only


destination file for download (file extension added according to format). Default NULL means a random tempfile().


color or black-and-white




In some cases the OSM server is unavailable, in these cases you will receive an error message from utils::download.file() with the message HTTP status '503 Service Unavailable'. You can confirm this by setting urlonly = TRUE, and then entering the URL in a web browser. the solution is either (1) change sources or (2) wait for the OSM servers to come back up.

See for license and copyright information.


a ggmap object (a classed raster object with a bounding box attribute)


David Kahle

See Also, ggmap()

ggmap documentation built on Nov. 19, 2023, 9:06 a.m.