MyNixOS website logo
Description

Design Shaded Contour Lines (or Tanaka) Maps.

The Tanaka method enhances the representation of topography on a map using shaded contour lines. In this simplified implementation of the method, north-west white contours represent illuminated topography and south-east black contours represent shaded topography. See Tanaka (1950) <doi:10.2307/211219>.

Tanaka

Cran version R-CMD-check Coverage status N. Download
Project Status: Active – The project has reached a stable, usablestate and is being activelydeveloped.

Also called "relief contours method", "illuminated contour method" or "shaded contour lines method", the Tanaka method1 enhances the representation of topography on a map by using shaded contour lines. The result is a 3D-like map.

This package is a simplified implementation of the Tanaka method, north-west white contours represent illuminated topography and south-east black contours represent shaded topography. Even if the results are quite satisfactory, a more refined method could be used based on the Kennelly and Kimerling's paper2.

tanaka is a small package with two functions:

  • tanaka() uses a terra object and displays the map directly;
  • tanaka_contour() builds the isopleth polygon layer.

The contour lines creation relies on mapiso, spatial manipulation and display rely on sf.

Installation

  • From CRAN
install.packages("tanaka")
  • Development version on GitHub
require(remotes)
install_github("riatelab/tanaka")

Demo

  • This example is based on the dataset shipped within the package.
library(tanaka)
library(terra)
ras <- rast(system.file("tif/elev.tif", package = "tanaka"))
tanaka(ras, breaks = seq(80,400,20), 
       legend.pos = "topright", legend.title = "Elevation\n(meters)")

  • This example is based on an elevation raster downloaded via elevatr.
library(tanaka)
library(elevatr)
library(terra)
# use elevatr to get elevation data
ras <- get_elev_raster(locations = data.frame(x = c(6.7, 7), y = c(45.8,46)),
                       z = 10, prj = "EPSG:4326", clip = "locations")
ras <- rast(ras)
# custom color palette
cols <- c("#F7E1C6", "#EED4C1", "#E5C9BE", "#DCBEBA", "#D3B3B6", "#CAA8B3", 
          "#C19CAF", "#B790AB", "#AC81A7", "#A073A1", "#95639D", "#885497", 
          "#7C4692", "#6B3D86", "#573775", "#433266", "#2F2C56", "#1B2847")
# display the map
tanaka(ras, breaks = seq(500,4800,250), col = cols)

library(terra)
library(sf)
library(tanaka)
library(mapsf)
# Download
tempzip <- tempfile()
tempfolder <- tempdir()
data_url <- paste0("http://cidportal.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/", 
                   "GHS_POP_GPW4_GLOBE_R2015A/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k/", 
                   "V1-0/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0.zip")
download.file(data_url, tempzip)
unzip(tempzip, exdir = tempfolder)
# Import
pop2015 <- rast(paste0(tempfolder, 
                       "/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0/",
                       "GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0.tif"))
# Mask raster
center <- st_as_sf(data.frame(x=425483.8, y=5608290), 
                   coords=(c("x","y")), 
                   crs = st_crs(pop2015))
center <- st_buffer(center, dist = 800000)
ras <- crop(pop2015, st_bbox(center)[c(1,3,2,4)])
# Smooth values
mat <- focalMat(x = ras, d = c(10000), type = "Gauss")
rassmooth <- focal(x = ras, w = mat, fun = sum, na.rm = TRUE)
# Map
bks <- c(0,25,50,100,250,500,750,1000,1750,2500,5000, 7500,10000)
mf_export(x = center, filename = "circle.png", width = 800, res = 100)
tanaka(x = rassmooth,
       breaks = bks,
       mask = center,
       col = hcl.colors(n = 12, palette = "Inferno"),
       shift = 2500,
       add = TRUE,
       legend.pos = "topleft",
       legend.title = "Inhabitants\nper km2")
mf_map(center, add = TRUE, border = "white", col = NA, lwd = 6)
mf_title(txt = "Smoothed Population Density")
mf_credits(paste0("T. Giraud, 2022\n",
                  "Data : European Commission, Joint Research Centre (JRC); ", 
                  "Columbia University, CIESIN (2015): GHS population grid, ", 
                  "derived from GPW4."))
text(-250000 ,6420000, "Gaussian filter, sigma = 10km", 
     adj = 0, font = 3, cex = .8, xpd = TRUE )
dev.off()

Alternative Package

The metR package allows to draw Tanaka contours with ggplot2.


1: Tanaka, K. (1950). The relief contour method of representing topography on maps. Geographical Review, 40(3), 444-456.
2: Kennelly, P., & Kimerling, A. J. (2001). Modifications of Tanaka's illuminated contour method. Cartography and Geographic Information Science, 28(2), 111-123.

Metadata

Version

0.4.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