MyNixOS website logo
Description

Download and Display Map Tiles.

To create maps from tiles, 'maptiles' downloads, composes and displays tiles from a large number of providers (e.g. 'OpenStreetMap', 'Stadia', 'Esri', 'CARTO', or 'Thunderforest').

maptiles

R-CMD-check Codecov testcoverage CRANstatus Project Status:Active – The project has reached a stable, usable state and is beingactivelydeveloped.

To create maps from tiles, maptiles downloads, composes and displays tiles from a large number of providers (e.g. OpenStreetMap, Stadia, Esri, CARTO, or Thunderforest).

Installation

You can install the released version of maptiles from CRAN with:

install.packages("maptiles")

You can install the development version of maptiles from GitHub with:

# install.packages("remotes")
remotes::install_github("riatelab/maptiles")

Demo

This is a basic example which shows you how to dowload and display OpenStreetMap tiles over North Carolina:

library(sf)
#> Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE
library(maptiles)
# import North Carolina counties
nc_raw <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
# Project to EPSG:3857
nc <- st_transform(nc_raw, "EPSG:3857")
# dowload tiles and compose raster (SpatRaster)
nc_osm <- get_tiles(nc, crop = TRUE)
# display map
plot_tiles(nc_osm)
# add Norh Carolina counties
plot(st_geometry(nc), col = NA, add = TRUE)
# add credit
mtext(text = get_credit("OpenStreetMap"), side = 1, line = -1, adj = .99)

maptiles gives access to a lot of tiles servers, but it is possible to add others. The following example demonstrates the setting of a map tiles server and how to cache the original tiles for future use:

# define the tile server parameters
osmpos <- create_provider(name = "CARTO.POSITRON",
                          url = "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
                          sub = c("a", "b", "c", "d"),
                          citation = "© OpenStreetMap contributors © CARTO ")
# dowload tiles and compose raster (SpatRaster)
nc_osmpos <- get_tiles(x = nc, provider = osmpos, crop = TRUE, 
                       cachedir = tempdir(), verbose = TRUE)
#> Zoom: 7
#> Source(s): © OpenStreetMap contributors © CARTO 
#> Cache directory: /tmp/RtmpdG8qYB/CARTO.POSITRON
#> 8 tiles
# display map
plot_tiles(nc_osmpos)
# display credits
mtext(text = get_credit(osmpos), side = 1, line = -1, adj = .99)

The following figure shows mini maps for most of the tiles providers available:

Projection

Original tiles use a projection known as “Web Mercator”, “WGS84 / Pseudo Mercator”, “Google Mercator”, “EPSG:3857” or “EPSG:900913”. In most cases get_tiles() uses the projection of its x argument to reproject the tiles. If you wish to avoid any deformation induced by the reprojection process, use “EPSG:3857” for x projection.

Attribution of map tiles

All maps available through maptiles are offered freely by various providers. The only counterpart from the user is to properly display an attribution text on the maps. get_credit() displays a short attribution text to add on each map using the downloaded tiles.

Alternatives

There are many alternative packages that pursue the same objective as maptiles. Some focus on a specific map tiles provider (e.g. Mapbox, Google, OpenStreetMap) or on a specific graphics device (ggplot2). The goal of maptiles is to be flexible enough to allow the use of different providers and to have a minimal number of robust and modern dependencies. However, depending on the use case, one of following packages may better suit your needs:

Note

Not to be confused with tilemaps, that “implements an algorithm for generating maps, known as tile maps, in which each region is represented by a single tile of the same shape and size.”

Metadata

Version

0.7.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • 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