get_carto: Get a Carto basemap

View source: R/get_carto.r

get_cartoR Documentation

Get a Carto basemap

Description

get_carto accesses a tile server for Carto basemaps and downloads/stitches map tiles/formats a map image. Vendored from ⁠\url{https://github.com/gregleleu/ggmap/blob/master/R/get_carto.R}⁠.

Usage

get_carto(
  bbox = c(left = -95.80204, bottom = 29.38048, right = -94.92313, top = 30.14344),
  zoom = 10,
  maptype = c("light_all", "dark_all", "light_nolabels", "light_only_labels",
    "dark_nolabels", "dark_only_labels", "rastertiles/voyager",
    "rastertiles/voyager_nolabels", "rastertiles/voyager_only_labels",
    "rastertiles/voyager_labels_under"),
  crop = TRUE,
  messaging = FALSE,
  urlonly = FALSE,
  color = c("color", "bw"),
  force = FALSE,
  where = tempdir(),
  https = FALSE,
  ...
)

get_carto_tile_dl_fail_log()

retry_carto_map_download()

Arguments

bbox

a bounding box in the format c(lowerleftlon, lowerleftlat, upperrightlon, upperrightlat).

zoom

a zoom level

maptype

light_all, dark_all, light_nolabels, light_only_labels, dark_nolabels, dark_only_labels, rastertiles/voyager, rastertiles/voyager_nolabels, rastertiles/voyager_only_labels, or rastertiles/voyager_labels_under.

crop

crop raw map tiles to specified bounding box. if FALSE, the resulting map will more than cover the bounding box specified.

messaging

turn messaging on/off

urlonly

return url only

color

color or black-and-white (use force = TRUE if you've already downloaded the images)

force

if the map is on file, should a new map be looked up?

where

where should the file drawer be located (without terminating "/")

https

if TRUE, queries an https endpoint so that web traffic between you and the tile server is encrypted using SSL.

...

...

Value

a ggmap object (a classed raster object with a bounding box attribute)

See Also

https://github.com/CartoDB/basemap-styles, [ggmap()]

Examples

## Not run: 
# some requires Google API key, see ?register_google; heavy network/time load


## basic usage
########################################

bbox <- c(left = -97.1268, bottom = 31.536245, right = -97.099334, top = 31.559652)

ggmap(get_carto(bbox, zoom = 13))
ggmap(get_carto(bbox, zoom = 14))
ggmap(get_carto(bbox, zoom = 15))
ggmap(get_carto(bbox, zoom = 16, messaging = TRUE))

place <- "mount everest"
(google <- get_googlemap(place, zoom = 9))
ggmap(google)
bbox_everest <- c(left = 86.05, bottom = 27.21, right = 87.81, top = 28.76)
ggmap(get_carto(bbox_everest, zoom = 9))



## map types
########################################

place <- "rio de janeiro"
google <- get_googlemap(place, zoom = 10)
ggmap(google)

bbox <- bb2bbox(attr(google, "bb"))

get_carto(bbox, maptype = "terrain") %>% ggmap()
get_carto(bbox, maptype = "terrain-background") %>% ggmap()
get_carto(bbox, maptype = "terrain-labels") %>% ggmap()
get_carto(bbox, maptype = "terrain-lines") %>% ggmap()
get_carto(bbox, maptype = "toner") %>% ggmap()
get_carto(bbox, maptype = "toner-2010") %>% ggmap()
get_carto(bbox, maptype = "toner-2011") %>% ggmap()
get_carto(bbox, maptype = "toner-background") %>% ggmap()
get_carto(bbox, maptype = "toner-hybrid") %>% ggmap()
get_carto(bbox, maptype = "toner-labels") %>% ggmap()
get_carto(bbox, maptype = "toner-lines") %>% ggmap()
get_carto(bbox, maptype = "toner-lite") %>% ggmap()
get_carto(bbox, maptype = "watercolor") %>% ggmap()


## zoom levels
########################################

get_carto(bbox, maptype = "watercolor", zoom = 11) %>% ggmap(extent = "device")
get_carto(bbox, maptype = "watercolor", zoom = 12) %>% ggmap(extent = "device")
get_carto(bbox, maptype = "watercolor", zoom = 13) %>% ggmap(extent = "device")
# get_carto(bbox, maptype = "watercolor", zoom = 14) %>% ggmap(extent = "device")
# get_carto(bbox, maptype = "watercolor", zoom = 15) %>% ggmap(extent = "device")
# get_carto(bbox, maptype = "watercolor", zoom = 16) %>% ggmap(extent = "device")
# get_carto(bbox, maptype = "watercolor", zoom = 17) %>% ggmap(extent = "device")
# get_carto(bbox, maptype = "watercolor", zoom = 18) %>% ggmap(extent = "device")


## https
########################################

bbox <- c(left = -97.1268, bottom = 31.536245, right = -97.099334, top = 31.559652)
get_carto(bbox, zoom = 14, urlonly = TRUE)
get_carto(bbox, zoom = 14, urlonly = TRUE, https = TRUE)
ggmap(get_carto(bbox, zoom = 15, https = TRUE, messaging = TRUE))


## more examples
########################################

gc <- geocode("rio de janeiro")

get_carto(bbox, zoom = 10) %>% ggmap() +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 2)

get_carto(bbox, zoom = 10, crop = FALSE) %>% ggmap() +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 2)

get_carto(bbox, zoom = 10, maptype = "watercolor") %>% ggmap() +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 2)

get_carto(bbox, zoom = 10, maptype = "toner") %>% ggmap() +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 2)


# continental united states labels
c("left" = -125, "bottom" = 25.75, "right" = -67, "top" = 49) %>%
  get_carto(zoom = 5, maptype = "toner-labels") %>%
  ggmap()




# accuracy check - white house
gc <- geocode("the white house")

qmap("the white house", zoom = 16) +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 3)

qmap("the white house", zoom = 16, source = "carto", maptype = "terrain") +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 3)

## End(Not run)


baslat/sak documentation built on April 14, 2025, 4:14 p.m.