osm.image: Get Open Street Map Tiles As A RasterStack

Description Usage Arguments Value Examples

View source: R/osmraster.R

Description

Get Open Street Map tiles as RasterStack object (requires package raster to be installed).

Usage

1
2
3
4
5
6
7
8
osm.image(x, zoomin = 0, zoom = NULL, type = NULL,
  forcedownload = FALSE, cachedir = NULL, progress = c("text",
  "none"), quiet = TRUE)

osm.raster(x, zoomin = 0, zoom = NULL, type = "osm",
  forcedownload = FALSE, cachedir = NULL, progress = c("text",
  "none"), quiet = TRUE, projection = NULL, crop = FALSE,
  filename = NULL, resample = "bilinear", ...)

Arguments

x

A bounding box as generated by sp::bbox() or prettymapr::searchbbox(). Must be in lon/lat (epsg:4326)! Alternatively, pass a Spatial* object to use the bounding box of that

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 recommended; adjust zoomin 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.

cachedir

The directory in which tiles should be cached. Defaults to getwd()/rosm.cache.

progress

A progress bar to use, or "none" to suppress progress updates

quiet

Pass FALSE to see more error messages, particularly if your tiles do not download/load properly.

projection

A map projection in which to reproject the RasterStack as generated by CRS() or Spatial*@proj4string. If a Spatial* object is passed as the first argument, this argument will be ignored.

crop

TRUE if results should be cropped to the specified bounding box (see x), FALSE otherwise.

filename

A filename to which the raster should be written (see raster::writeRaster()). Use a ".tif" extension to write as a GeoTIFF.

resample

One of "ngb" (nearest neighbour) or "bilinear". Passed to projectRaster.

...

Arguments passed on to raster::writeRaster() if filename is specified.

Value

A projected RasterStack of the fused tiles.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library(cartography)
library(raster)
library(prettymapr)

ns <- makebbox(47.2, -59.7, 43.3, -66.4)
x <- osm.raster(ns, projection=CRS("+init=epsg:26920"), crop=TRUE)
# plot using plotRGB (from the raster package)
plotRGB(x)

# use a Spatial* object as the first argument to automatically set the bounding
# box and projection
data(nuts2006)
spdf <- nuts0.spdf[nuts0.spdf$id=="DE",]
x <- osm.raster(spdf, type="thunderforestlandscape")
plotRGB(x)

# write to disk by passing a filename argument (use .tif extension to write GeoTIFF)
osm.raster(ns, projection=CRS("+init=epsg:26920"), crop=TRUE, filename="ns.tif")

# can also write Raster* objects using osm.raster
osm.raster(x, filename="germany.tif")

rosm documentation built on July 22, 2019, 9:04 a.m.