Obtain imagery or elevation tiles by location query. The first argument loc may be a spatial object (sp, raster, sf) or a 2-column matrix with a single longitude and latitude value. Use buffer to define a width and height to pad around the raw longitude and latitude in metres. If loc has an extent, then buffer is ignored.

read_tiles(
  x,
  buffer,
  type = "mapbox.satellite",
  crop_to_buffer = TRUE,
  format = NULL,
  ...,
  zoom = NULL,
  debug = FALSE,
  max_tiles = NULL,
  base_url = NULL,
  verbose = TRUE,
  filename = ""
)

get_tiles(
  x,
  buffer,
  type = "mapbox.satellite",
  crop_to_buffer = TRUE,
  format = NULL,
  ...,
  zoom = NULL,
  debug = FALSE,
  max_tiles = NULL,
  base_url = NULL,
  verbose = TRUE
)

Arguments

x

a longitude, latitude pair of coordinates, or a spatial object

buffer

width in metres to extend around the location, ignored if 'x' is a spatial object with extent

type

character string of provider imagery type (see Details)

crop_to_buffer

crop to the user extent, used for creation of output objects (otherwise is padded tile extent)

format

tile format to use, defaults to "jpg" for Mapbox satellite imagery and "png" otherwise

...

arguments passed to internal function, specifically base_url (see Details)

zoom

desired zoom for tiles, use with caution - if NULL is chosen automatically

debug

optionally avoid actual download, but print out what would be downloaded in non-debug mode

max_tiles

maximum number of tiles - if NULL is set by zoom constraints

base_url

tile provider URL expert use only

verbose

report messages or suppress them

filename

purely for read_tiles() this is passed down to the the terra package function 'merge'

Value

A list with files downloaded in character vector, a data frame of the tile indices, the zoom level used and the extent in xmin,xmax,ymin,ymax form.

Details

get_tiles() may be run with no arguments, and will download (and report on) the default tile source at zoom 0. Arguments type, zoom (or max_tiles), format may be used without setting loc or buffer and the entire world extent will be used. Please use with caution! There is no maximum on what will be downloaded, but it can be interrupted at any time.

Use debug = TRUE to avoid download and simply report on what would be done.

Available types are 'elevation-tiles-prod' for AWS elevation tiles, and 'mapbox.satellite', 'mapbox.terrain-rgb'. (The RGB terrain values are not unpacked.)

Function read_tiles() will match what get_tiles() does and actually build a raster object.

See also

get_tiles_zoom get_tiles_dim get_tiles_buffer

Examples

if (!is.null(get_api_key())) {
   tile_info <- get_tiles(ext(146, 147, -43, -42), type = "mapbox.satellite", zoom = 5)
}
#> Warning: no mapbox key found
#> 
#> To set your Mapbox API key obtain a key from https://account.mapbox.com/access-tokens/
#> 
#> 1) Run this to set for the session 'Sys.setenv(MAPBOX_API_KEY=<yourkey>)'
#> 
#> OR,
#> 
#> 2) To set permanently store 'MAPBOX_API_KEY=<yourkey>' in ~/.Renviron
#> 
#> See 'help(ceramic::get_api_key)'