staticmap_getStamenmapBrick: Create a rasterBrick from stamenmap tiles

Description Usage Arguments Value Note See Also Examples

View source: R/staticmap_getStamenmapBrick.R

Description

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."

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
staticmap_getStamenmapBrick(
  centerLon = NULL,
  centerLat = NULL,
  maptype = "terrain",
  zoom = 12,
  width = 640,
  height = 640,
  bbox = NULL,
  crs = sp::CRS("+init=epsg:4326"),
  tileCacheDir = tempdir()
)

Arguments

centerLon

map center longitude

centerLat

map center latitude

maptype

map type

zoom

map zoom level; corresponds to ggmap::get_map() zoom level

width

width of image, in pixels

height

height of image, in pixels

bbox

bounding box vector (lonLo, latLo, lonHi, latHi). If not null, centerLon, centerLat, and zoom are ignored.

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 raster::projectRaster.

tileCacheDir

Optional location for cached tiles.

Value

A rasterBrick object which can be plotted with staticmap_plotRasterBrick() or raster::plotRGB() and serve as a base plot.

Note

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.

See Also

staticmap_getRasterBrick

staticmap_plotRasterBrick

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
# Fail gracefully if any resources are not available
try({

rasterBrick <- staticmap_getStamenmapBrick(-122.3318, 47.668)
staticmap_plotRasterBrick(rasterBrick)

}, silent = FALSE)

## End(Not run)

PWFSLSmoke documentation built on Nov. 23, 2021, 5:06 p.m.