getBasemapRaster: getBasemapRaster

Description Usage Arguments Value Examples

View source: R/getBasemapRaster.r

Description

This function obtains an RGB raster from any of the available base maps in the (incredible!) open source leaflet package. It is meant to replace - in a way - the ggmap function, which now requires an API key with Google. It is in some ways more flexible: you can set the lat and long limits strictly, it returns a projected raster which can be reprojected to any other resolution, and it can access any of the remarkable diversity of high quality mapping option at: http://leaflet-extras.github.io/leaflet-providers/preview/. Note that it creates a "png" and "html" and places it in a given directory, and does not delete them.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
getBasemapRaster(
  xmin,
  xmax,
  ymin,
  ymax,
  map.types = "Esri.WorldPhysical",
  directory = ".",
  filename = "basemap",
  width = 1000,
  height = 1000,
  zoom = 1,
  plotme = TRUE,
  ...
)

Arguments

map.types

Character specification for the base maps. see http://leaflet-extras.github.io/leaflet-providers/preview/ for available options. Favorites include: Esri.WorldPhysical (default), Esri.WorldTerrain, Esri.NatGeoWorldMap

directory

directory to save the html and png files

filename

name of png and html files

zoom

this is the zoom argument from webshot; it also has some complicated effect on the resolution of the final image.

plotme

whether or not to plot the raster with plotRGB. Note that high resolution rasters are reduced in rendering within R by default ... this can be modified with plotRGB options.

xmin, xmax, ymin, ymax

Limits (in longitude and latitude) of desired map raster.

width, height

approximate width and height of final raster; this is VERY approximate because the final raster is cropped around the desired limits and because there is some

Value

An RGB raster, i.e. one with three levels for each of the colors. Note, the projection of the returned raster is the Spherical Mercator (EPSG:3857) - used for global tiling and "native" to mapview (and leaflet).

Examples

1
2
3
4
5
6
# SE Alaska
SEalaska.topo <- getBasemapRaster(-138,-130, 56, 60, "OpenTopoMap")
# for a ggPlot use this function (from RStoolbox): 
ggRGB(SEalaska.topo, 1, 2, 3, coord_equal = FALSE)
# labeled DC map, high resolution
dc.natgeo <- getBasemapRaster(-77.5,-76.5, 38.5, 39.25, map.types = "Esri.NatGeoWorldMap", width = 1000, height = 1000, zoom = 8)

ABoVE-AotM/above documentation built on May 28, 2020, 6:08 a.m.