Learn R Programming

rosm (version 0.1.3)

osm.plot: Plot Open Street Map Tiles

Description

Plot Open Street Map tiles using rasterImage and sp::plot. Define your own tile sources by creating a tile url function in the global environment, although most http://wiki.openstreetmap.org/wiki/Tile_servers{OSM listed} servers are included. See osm.types for types options. By default tiles are plotted in the Spherical Mercator projection (https://en.wikipedia.org/wiki/Web_Mercator{epsg:3857}); pass project=FALSE to keep lat/lon coordinates.

Usage

osm.plot(bbox, zoomin = 0, zoom = NULL, type = "osm",
  forcedownload = FALSE, stoponlargerequest = TRUE, fusetiles = TRUE,
  cachedir = NULL, res = 150, project = TRUE, ...)

Arguments

bbox
A bounding box as generated by sp::bbox() or prettymapr::searchbbox()
zoomin
The amount by which to adjust the automatically calculated zoom (or manually specified if the zoom parameter is passed). Use +1 to zoom in, or -1 to zoom out.
zoom
Manually specify the zoom level (not reccomended; adjust zoomin or res instead.
type
A map type; one of that returned by osm.types. User defined types are possible by defining tile.url.TYPENAME <- function(xtile, ytile, zoom){} and passing TYPENAME as the type argument.
forcedownload
TRUE if cached tiles should be re-downloaded. Useful if some tiles are corrupted.
stoponlargerequest
By default osm.plot will only load 32 tiles at a time. If plotting at a higher resolution it may be necessary to pass true here.
fusetiles
TRUE if tiles should be fused into a single image. This is the default because white lines appear between tiles if it is set to FALSE. PDFs appear not to have this problem, so when plotting large, high resolution PDFs it may be f
cachedir
The directory in which tiles should be cached. Defaults to getwd()/rosm.cache.
res
The resolution used to calculate scale.
project
TRUE if tiles should be projected to a pseudo-mercator projection, FALSE if lat/lon should be maintained. Becuase sp::plot adjusts the aspect according to latitude for lat/lon coordinates, this makes little differenc
...
Additional parameters to be passed on to the first call to sp::plot

Examples

Run this code
library(prettymapr)
ns <- makebbox(47.2, -59.7, 43.3, -66.4)
osm.plot(ns)
osm.plot(ns, type="mapquestsat")
prettymap(osm.plot(ns), scale.style="ticks", scale.tick.cex=0)

tile.url.darkmatter <- function(xtile, ytile, zoom) {
  paste0(paste("http://a.basemaps.cartocdn.com/dark_all",
                            zoom, xtile, ytile, sep="/"), ".png")
}
osm.plot(ns, type="darkmatter")

Run the code above in your browser using DataLab