Skip to content

Instantly share code, notes, and snippets.

@rCarto
Created April 11, 2020 12:16
Show Gist options
  • Select an option

  • Save rCarto/facb923e14bfb4804fa835b80ed3fd33 to your computer and use it in GitHub Desktop.

Select an option

Save rCarto/facb923e14bfb4804fa835b80ed3fd33 to your computer and use it in GitHub Desktop.
library(cartography)
library(sf)
#> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0

# create an sf object centered on Tizi Ouzou city
tizi <- data.frame(name = "Tizi Ouzou", longitude = 4.06, latitude = 36.71)
tizi <- st_as_sf(tizi, coords = c("longitude", "latitude"), crs = 4326)
tizi <- st_transform(tizi, 3857)
tizi <- st_buffer(tizi, 5000)

token = 'YOUR_MAPBOX_API_KEY'

type = list(src = "MapBox" , 
            q = 'https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.jpg?access_token=XXXXXX', 
            sub = NA, cit = "MapBox Tiles")

tizimapbox <- getTiles(x = tizi, type = type, crop = TRUE, verbose = FALSE, 
                       zoom = 13,
                       apikey = token, cachedir = "tata", forceDownload = FALSE)
class(tizimapbox)
#> [1] "RasterBrick"
#> attr(,"package")
#> [1] "raster"
tilesLayer(tizimapbox)

Created on 2020-04-11 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment