R/staticmap_getStamenmapBrick.R
staticmap_getStamenmapBrick.Rd
Downloads a PNG from the stamenmap tile server and creates a
raster::rasterBrick
object with layers for red, green, and blue. This
can then passed as the rasterBrick
object to the
staticmap_plotRasterBrick()
function for plotting.
Stamen maps tiles are freely available (April, 2019) and are described at the following URL:
http://maps.stamen.com/#terrain/12/37.7706/-122.3782
"These tiles are made available as part of the CityTracking project, funded by the Knight Foundation, in which Stamen is building web services and open source tools to display public data in easy-to-understand, highly visual ways."
staticmap_getStamenmapBrick( centerLon = NULL, centerLat = NULL, maptype = "terrain", zoom = 12, width = 640, height = 640, bbox = NULL, crs = sp::CRS("+init=epsg:4326"), tileCacheDir = tempdir() )
centerLon | map center longitude |
---|---|
centerLat | map center latitude |
maptype | map type |
zoom | map zoom level; corresponds to |
width | width of image, in pixels |
height | height of image, in pixels |
bbox | bounding box vector (lonLo, latLo, lonHi, latHi). If not null,
|
crs | object of class CRS. The Coordinate Reference System (CRS) for the
returned map. If the CRS of the downloaded map does not match, it will be
projected to the specified CRS using |
tileCacheDir | Optional location for cached tiles. |
A rasterBrick object which can be plotted with
staticmap_plotRasterBrick()
or raster::plotRGB()
and serve as a
base plot.
The spatial reference of the image when it is downloaded is 3857. If the crs argument is different, projecting may cause the size and extent of the image to differ very slightly from the input, on a scale of 1-2 pixels or 10^-3 degrees.
If bbox is specified and the bbox aspect ratio does not match the width/height aspect ratio the extent is resized to prevent the map image from appearing stretched, so the map extent may not match the bbox argument exactly.
if (FALSE) { # Fail gracefully if any resources are not available try({ rasterBrick <- staticmap_getStamenmapBrick(-122.3318, 47.668) staticmap_plotRasterBrick(rasterBrick) }, silent = FALSE) }