Learn R Programming

cartography (version 2.1.0)

getTiles: Get Tiles from Open Map Servers

Description

Get map tiles based on a spatial object extent. Maps can be fetched from various open map servers.

Usage

getTiles(x, spdf, type = "osm", zoom = NULL, crop = FALSE)

Arguments

x

an sf object, a simple feature collection or a Spatial*DataFrame.

spdf

deprecated, a Spatial*DataFrame with a valid projection attribute.

type

the tile server from which to get the map, one of "osm", "opencycle", "hotstyle", "loviniahike", "loviniacycle", "hikebike", "osmgrayscale", "stamenbw", "stamenwatercolor", "osmtransport", "thunderforestlandscape", "thunderforestoutdoors", "cartodark", "cartolight".

zoom

the zoom level. If null, it is determined automatically (see Details).

crop

TRUE if results should be cropped to the specified spdf extent, FALSE otherwise.

Value

A RatserBrick is returned.

Details

Zoom levels are described on the OpenStreetMap wiki: http://wiki.openstreetmap.org/wiki/Zoom_levels.

See Also

tilesLayer

Examples

Run this code
# NOT RUN {
library(sp)
data("nuts2006")
# extract Denmark
spdf <- nuts0.spdf[nuts0.spdf$id=="DK",]
# Download the tiles, extent = Denmark
den <- getTiles(spdf = spdf, type = "osm", crop = TRUE)
class(den)
# Plot the tiles
tilesLayer(den)
# Map tiles sources
mtext(text = "<U+00A9> OpenStreetMap contributors, under CC BY SA.",
      side = 1, adj = 0, cex = 0.7, font = 3)

library(sf)
mtq <- st_read(system.file("shape/martinique.shp", package="cartography"))
# Download the tiles, extent = Martinique
mtqOSM <- getTiles(x = mtq, type = "osm", crop = TRUE)
# Plot the tiles
tilesLayer(mtqOSM)
# Plot countries
plot(st_geometry(mtq), add=TRUE)
mtext(text = "<U+00A9> OpenStreetMap contributors, under CC BY SA.",
      side = 1, adj = 0, cex = 0.7, font = 3)
# }

Run the code above in your browser using DataLab