MyNixOS website logo
Description

Accessing Spatial Basemaps in R.

A lightweight package to access spatial basemaps from open sources such as 'OpenStreetMap', 'Carto', 'Mapbox' and others in R.

basemaps

CRAN version CRAN downloads CRAN checks R-CMD-check AppVeyor build status Coverage Package dependencies

basemaps is a lightweight R package to download and cache spatial basemaps from open sources such as OpenStreetMap, Stamen, Stadia, Thunderforest, Carto, Mapbox, Esri and others. Retrieved basemaps are translated into and returned as classes of choice, such as terra, stars, raster, ggplot, mapview, magick, or as files, such as png or geotif. The package aims to ease the use of basemaps in different contexts by providing a function interface as minimalist as possible.

Installation

Install the latest stable release of basemaps from CRAN:

install.packages("basemaps")

Install the latest development version of basemaps from GitHub:

devtools::install_github("16EAGLE/basemaps")

Get started

All available map services and map types can be printed using get_maptypes(). The basemap() function and its class-specific aliases facilitate (down)loading a basemap and returning it as a class of choice. Map preferences that should be used during a session can be set as defaults using set_defaults().

library(basemaps)
data(ext)
# or use draw_ext() to interactively draw an extent yourself

# view all available maps
get_maptypes()

# set defaults for the basemap
set_defaults(map_service = "osm", map_type = "topographic")

# load and return basemap map as class of choice, e.g. as image using magick:
basemap_magick(ext)
#> Loading basemap 'topographic' from map service 'osm'...
# or as plot:
basemap_plot(ext)

# or as ggplot2:
basemap_ggplot(ext)

# or as ggplot2 layer:
library(ggplot2)
ggplot() + 
  basemap_gglayer(ext) +
  scale_fill_identity() + 
  coord_sf()
# or as mapview:
basemap_mapview(ext)
# or as spatial classes, such as raster:
basemap_raster(ext)

# or terra:
basemap_raster(ext)

# or stars:
basemap_stars(ext)

# or return files, e.g. geotif
basemap_geotif(ext)
#> [1] "basemap_20220922214954.tif"

# or png:
basemap_png(ext)
#> [1] "osm_topographic_bg_2022-09-22_12-00-00.png"

Map examples

basemaps supports a variety of map services and types (which can be printed using get_maptypes()). A selection of available map types is shown below. For a complete table of available map types, see supported services and maps.

basemap_magick(ext, map_service = "osm", map_type = "streets")
#> Loading basemap 'streets' from map service 'osm'...
basemap_magick(ext, map_service = "mapbox", map_type = "satellite")
#> Loading basemap 'satellite' from map service 'mapbox'...
basemap_magick(ext, map_service = "mapbox", map_type = "hybrid")
#> Loading basemap 'hybrid' from map service 'mapbox'...
basemap_magick(ext, map_service = "mapbox", map_type = "streets")
#> Loading basemap 'streets' from map service 'mapbox'...
basemap_magick(ext, map_service = "mapbox", map_type = "terrain")
#> Loading basemap 'terrain' from map service 'mapbox'...
basemap_magick(ext, map_service = "osm_stamen", map_type = "terrain_bg")
#> Loading basemap 'terrain_bg' from map service 'osm_stamen'...
basemap_magick(ext, map_service = "osm_stamen", map_type = "toner")
#> Loading basemap 'toner' from map service 'osm_stamen'...
basemap_magick(ext, map_service = "osm_stamen", map_type = "watercolor")
#> Loading basemap 'watercolor' from map service 'osm_stamen'...
basemap_magick(ext, map_service = "osm_thunderforest", map_type = "transport")
#> Loading basemap 'transport' from map service 'osm_thunderforest'...
basemap_magick(ext, map_service = "osm_thunderforest", map_type = "landscape")
#> Loading basemap 'landscape' from map service 'osm_thunderforest'...
basemap_magick(ext, map_service = "osm_thunderforest", map_type = "outdoors")
#> Loading basemap 'outdoors' from map service 'osm_thunderforest'...
basemap_magick(ext, map_service = "osm_thunderforest", map_type = "atlas")
#> Loading basemap 'atlas' from map service 'osm_thunderforest'...
basemap_magick(ext, map_service = "carto", map_type = "light")
#> Loading basemap 'light' from map service 'carto'...
basemap_magick(ext, map_service = "carto", map_type = "dark")
#> Loading basemap 'dark' from map service 'carto'...

Supported services and maps

This table lists all currently implemented map services and map types and indicates whether they can be used without a map token (requiring registration at the respective service) or not.

map_servicemap_typemap_token required?
osmstreetsno
osmstreets_deno
osmtopographicno
osm_stamentoneryes, register: https://stadiamaps.com/
osm_stamentoner_bgyes, register: https://stadiamaps.com/
osm_stamenterrainyes, register: https://stadiamaps.com/
osm_stamenterrain_bgyes, register: https://stadiamaps.com/
osm_stamenwatercoloryes, register: https://stadiamaps.com/
osm_stadiaalidade_smoothyes, register: https://stadiamaps.com/
osm_stadiaalidade_smooth_darkyes, register: https://stadiamaps.com/
osm_stadiaoutdoorsyes, register: https://stadiamaps.com/
osm_stadiaosm_brightyes, register: https://stadiamaps.com/
osm_thunderforestcycleyes, register: https://www.thunderforest.com/
osm_thunderforesttransportyes, register: https://www.thunderforest.com/
osm_thunderforestlandscapeyes, register: https://www.thunderforest.com/
osm_thunderforestoutdoorsyes, register: https://www.thunderforest.com/
osm_thunderforesttransport_darkyes, register: https://www.thunderforest.com/
osm_thunderforestspinalyes, register: https://www.thunderforest.com/
osm_thunderforestpioneeryes, register: https://www.thunderforest.com/
osm_thunderforestmobile_atlasyes, register: https://www.thunderforest.com/
osm_thunderforestneighbourhoodyes, register: https://www.thunderforest.com/
osm_thunderforestatlasyes, register: https://www.thunderforest.com/
cartolightno
cartolight_no_labelsno
cartolight_only_labelsno
cartodarkno
cartodark_no_labelsno
cartodark_only_labelsno
cartovoyagerno
cartovoyager_no_labelsno
cartovoyager_only_labelsno
cartovoyager_labels_underno
mapboxstreetsyes, register: https://mapbox.com
mapboxoutdoorsyes, register: https://mapbox.com
mapboxlightyes, register: https://mapbox.com
mapboxdarkyes, register: https://mapbox.com
mapboxsatelliteyes, register: https://mapbox.com
mapboxhybridyes, register: https://mapbox.com
mapboxterrainyes, register: https://mapbox.com
esrinatgeo_world_mapno
esriusa_topo_mapsno
esriworld_imageryno
esriworld_physical_mapno
esriworld_shaded_reliefno
esriworld_street_mapno
esriworld_terrain_baseno
esriworld_topo_mapno
esriworld_dark_gray_baseno
esriworld_dark_gray_referenceno
esriworld_light_gray_baseno
esriworld_light_gray_referenceno
esriworld_hillshade_darkno
esriworld_hillshadeno
esriworld_ocean_baseno
esriworld_ocean_referenceno
esriantarctic_imageryno
esriarctic_imageryno
esriarctic_ocean_baseno
esriarctic_ocean_referenceno
esriworld_boundaries_and_places_alternateno
esriworld_boundaries_and_placesno
esriworld_reference_overlayno
esriworld_transportationno
esridelorme_world_base_mapno
esriworld_navigation_chartsno

Available functions

  • get_maptypes() returns every supported map service and map type that can be used as input to the map_service and map_type arguments of set_defaults(), basemap() or associated functions.
  • draw_ext() lets you draw an extent on an interactive map.
  • set_defaults(), get_defaults() and reset_defaults() set, get or reset the defaults of all map arguments passed to basemap() or associated functions.
  • basemap() and its aliases basemap_raster(), basemap_stars(), basemap_mapview(), basemap_plot(), basemap_ggplot(), basemap_gglayer(), basemap_magick(), basemap_png() and basemap_geotif() (down)load and cache a basemap of a defined extent ext, map_service and map_type and return it as an object of the defined class.
  • gg_raster() plots objects of class SpatRaster, RasterLayer, RasterBrick or RasterStack as ggplot2.
  • flush_cache() deletes all cached map tiles and basemaps.

Related packages

If you are interested in obtaining basemaps, you also may want to have a look at ceramic, an R package developed by Michael Sumner with a similar goal.

The underpinning code of basemaps was originally developed for moveVis and has been detached to allow its general use.



© Mapbox © Thunderforest © Stamen © Carto © Esri. Many thanks to the creators of reprex v2.0.2 which this README was compiled with.

Metadata

Version

0.0.7

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows