Skip to content

Commit

Permalink
update with 3D maps
Browse files Browse the repository at this point in the history
  • Loading branch information
rCarto committed Nov 29, 2023
1 parent 282de89 commit 6d2868e
Show file tree
Hide file tree
Showing 18 changed files with 1,177 additions and 328 deletions.
160 changes: 55 additions & 105 deletions 04_cartes_3D.qmd
Original file line number Diff line number Diff line change
@@ -1,127 +1,77 @@
---
output: html_document
editor_options:
chunk_output_type: console
---

```{r knitr4_init, echo=FALSE, cache=FALSE}
library(knitr)
## Global options
options(max.print="90")
opts_chunk$set(echo=TRUE,
cache=TRUE,
prompt=FALSE,
tidy=FALSE,
comment=NA,
message=FALSE,
warning=FALSE,
fig.align='center',
fig.height=7,
fig.width=7,
sm=TRUE)
opts_knit$set(width=90)
options(width = 90)
```

# Les cartes en 3D

## linemap

Le package `linemap` [@R-linemap] permet de réaliser des cartes composées de lignes.

```{r linemap}
#| fig-width: 7
#| fig-height: 8
#| eval: true
library(linemap)
library(sf)
library(terra)
library(mapsf)
# import des communes du Lot
com <- st_read("data/lot46.gpkg", layer = "commune", quiet = TRUE)
com <- st_transform(com, 3035)
# import du data.frame de population
pop <- read.csv("data/pop.csv")
# cartographie
th <- mf_theme("green")
mf_init(com)
linemap(
x = pop,
var = "Ind",
k = 10,
threshold = 15,
lwd = 1,
col = th$bg,
border = th$fg,
add = T)
mf_title("Population du Lot, 2015")
mf_credits("Giraud & Pecout, 2021\nDonnées carroyées – Carreau de 1km, INSEE - 2019")
com <- st_read("data/lot.gpkg", layer = "communes", quiet = TRUE)
elev <- rast("data/elev.tif")
cahors <- st_buffer(com[com$NOM_COM == "Cahors", ], 5000)
elev_cahors <- crop(elev, cahors)
mf_theme("green")
mf_map(cahors, col = NA, border = NA, expandBB = c(-.05,0,0.05,0))
linemap(x = elev_cahors,
k = 5,
bg = getOption("mapsf.bg"),
add = TRUE, lwd = 1)
mf_title("Altitude vers Cahors")
mf_credits("Giraud & Pecout, 2023")
```




## Relief Tanaka

Nous utilisons le package `tanaka` [@Tanaka20] qui met à disposition une méthode [@Tanaka50] utilisée pour améliorer la perception du relief.
Nous utilisons le package `tanaka` [@R-tanaka] qui met à disposition une méthode [@Tanaka50] utilisée pour améliorer la perception du relief.

```{r tanaka}
library(tanaka)
library(terra)
# import du raster de population
rpop <- rast("data/pop.tif")
# import des communes du Lot
com <- st_read("data/lot46.gpkg", layer = "commune", quiet = TRUE)
com <- st_transform(com, st_crs(rpop))
# lissage du raster
mat <- focalMat(x = rpop, d = c(1500), type = "Gauss")
rpopl <- focal(x = rpop, w = mat, fun = sum, na.rm = TRUE)
# cartographie
col1 <- hcl.colors(8, "Rocket", alpha = .3, rev = T)
col2 <- hcl.colors(8, "Rocket", alpha = 1, rev = T)[-1]
mf_theme("agolalight")
mf_init(com)
tanaka(x = rpopl, breaks = c(0,10,25, 50,100,250,500,750, 1972),
col = col1, light = NA, dark = NA, add = T, legend.pos = "n")
tanaka(x = rpopl, breaks = c(0,10,25,50,100,250,500,786),
col = col2, add = T, mask = com, legend.pos = "n")
mf_legend(type = "choro", pos = "topleft",
val = c(0,10,25,50,100,250,500,786), pal = col2,
bg = "#EDF4F5", fg = NA, frame = T, val_rnd = 0,
title = "Habitants\npar km2")
mf_title("Population lissée du Lot, 2015")
mf_credits("Giraud & Pecout, 2021\nINSEE, Données carroyées Filosofi 2015",
bg = "#EDF4F5")
```


```{block2, type = 'linky'}
[The tanaka package](https://rgeomatic.hypotheses.org/1758)
```


## rayshader

Le package `rayshader` [@R-rayshader] permet de réaliser de belles cartes en relief mais il n'est pas très facile à prendre en main. Le package `rayvista` [@R-rayvista] s'appuie sur `rayshader` et facilite la création de représentations 3D du terrain.
`rayvista` n'est pas sur le CRAN.


```{r rayshade,eval=FALSE}
# remotes::install_github("https://github.com/h-a-graham/rayvista")
library(rayshader)
library(rayvista)
zone <- plot_3d_vista(
lat = 44.9320, long = 1.6905, radius = 4000,
zscale = 1.5, phi = 30, theta = 120,
windowsize = c(1000, 600),
baseshape = "circle",
overlay_detail = 15,
elevation_detail = 14,
background = "grey20"
)
png("img/mezels.png", width = 1000, height = 600)
render_camera(zoom = .4)
render_depth(focus = 0.4, focallength = 55, vignette = TRUE)
dev.off()
mf_theme("candy")
mf_map(cahors, col = NA, border = NA)
tanaka(elev_cahors,
breaks = seq(100,375,25),
col = hcl.colors(11, "Lajolla"),
add = TRUE)
mf_title("Altitude vers Cahors")
mf_credits("Giraud & Pecout, 2023")
```

```{r, fig.align='center', echo=FALSE, out.width='100%'}
knitr::include_graphics("img/mezels.png")
```
<!-- ## rayshader -->

<!-- Le package `rayshader` [@R-rayshader] permet de réaliser de belles cartes en relief mais il n'est pas très facile à prendre en main. Le package `rayvista` [@R-rayvista] s'appuie sur `rayshader` et facilite la création de représentations 3D du terrain. -->
<!-- `rayvista` n'est pas sur le CRAN. -->


<!-- ```{r rayshade,eval=FALSE} -->
<!-- # remotes::install_github("https://github.com/h-a-graham/rayvista") -->
<!-- library(rayshader) -->
<!-- library(rayvista) -->

<!-- zone <- plot_3d_vista( -->
<!-- lat = 44.9320, long = 1.6905, radius = 4000, -->
<!-- zscale = 1.5, phi = 30, theta = 120, -->
<!-- windowsize = c(1000, 600), -->
<!-- baseshape = "circle", -->
<!-- overlay_detail = 15, -->
<!-- elevation_detail = 14, -->
<!-- background = "grey20" -->
<!-- ) -->
<!-- png("img/mezels.png", width = 1000, height = 600) -->
<!-- render_camera(zoom = .4) -->
<!-- render_depth(focus = 0.4, focallength = 55, vignette = TRUE) -->
<!-- dev.off() -->
<!-- ``` -->

<!-- ```{r, fig.align='center', echo=FALSE, out.width='100%'} -->
<!-- # knitr::include_graphics("img/mezels.png") -->
<!-- ``` -->
17 changes: 11 additions & 6 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ book:
date-format: "D MMM YYYY"
doi: 10.5281/zenodo.5905734
search: true
repo-url: https://github.com/rcarto/geomatique_avec_r/
repo-url: https://github.com/rcarto/cartographie_avec_r/
cover-image: img/globe-africa-solid.svg
page-footer:
right: "<img src='img/logos-footer.png' width=290px />"
Expand All @@ -52,13 +52,18 @@ book:
open-graph: true
chapters:
- index.qmd
- 01_mapsf.qmd
- 02_semiologie.qmd
- 03_types_de_cartes.qmd
- 04_mise_en_page.qmd
- part: "**Cartographie thématique**"
chapters:
- 01_mapsf.qmd
- 02_semiologie.qmd
- 03_types_de_cartes.qmd
- 04_mise_en_page.qmd
- part: "**Cartographie 3D et Anamorphoses**"
chapters:
- 04_cartes_3D.qmd
- 05_anamorphoses.qmd
- 2000_references.qmd
appendices:
- 05_anamorphoses.qmd
- 2002_data.qmd

knitr:
Expand Down
11 changes: 5 additions & 6 deletions book.bib
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ @Manual{R-rayshader
@Manual{R-linemap,
title = {linemap: Line Maps},
author = {Timothée Giraud},
year = {2017},
note = {R package version 0.1.0},
year = {2023},
note = {R package version 0.3.0},
url = {https://CRAN.R-project.org/package=linemap},
}

Expand Down Expand Up @@ -810,16 +810,15 @@ @Article{Tennekes18
doi = {10.18637/jss.v084.i06},
}

@Manual{Tanaka20,
@Manual{R-tanaka,
title = {tanaka: Design Shaded Contour Lines (or Tanaka) Maps},
author = {Timothée Giraud},
year = {2020},
note = {R package version 0.1.3},
year = {2023},
note = {R package version 0.4.0},
url = {https://CRAN.R-project.org/package=tanaka},
}



@Manual{R-rayvista,
title = {rayvista: A {rayshader} plugin to simplify plotting 3d elevation with map
overlays},
Expand Down
60 changes: 44 additions & 16 deletions docs/01_mapsf.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Basculer la barre latérale" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<i class="bi bi-layout-text-sidebar-reverse"></i>
</button>
<nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./01_mapsf.html"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">mapsf</span></a></li></ol></nav>
<nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./01_mapsf.html"><strong>Cartographie thématique</strong></a></li><li class="breadcrumb-item"><a href="./01_mapsf.html"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">mapsf</span></a></li></ol></nav>
<a class="flex-grow-1" role="button" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Basculer la barre latérale" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
</a>
<button type="button" class="btn quarto-search-button" aria-label="" onclick="window.quartoOpenSearch();">
Expand All @@ -119,7 +119,7 @@
<div class="sidebar-title mb-0 py-0">
<a href="./">Cartographie avec R</a>
<div class="sidebar-tools-main">
<a href="https://github.com/rcarto/geomatique_avec_r/" rel="" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-github"></i></a>
<a href="https://github.com/rcarto/cartographie_avec_r/" rel="" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-github"></i></a>
</div>
</div>
</div>
Expand All @@ -136,30 +136,64 @@
<span class="menu-text"><em>Préambule</em></span></a>
</div>
</li>
<li class="sidebar-item">
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">
<span class="menu-text"><strong>Cartographie thématique</strong></span></a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true" aria-label="Basculer la section">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./01_mapsf.html" class="sidebar-item-text sidebar-link active">
<span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">mapsf</span></span></a>
</div>
</li>
<li class="sidebar-item">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./02_semiologie.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">La sémiologie graphique</span></span></a>
</div>
</li>
<li class="sidebar-item">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./03_types_de_cartes.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Les types de cartes</span></span></a>
</div>
</li>
<li class="sidebar-item">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./04_mise_en_page.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">La mise en page</span></span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="true">
<span class="menu-text"><strong>Cartographie 3D et Anamorphoses</strong></span></a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="true" aria-label="Basculer la section">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./04_cartes_3D.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Les cartes en 3D</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./05_anamorphoses.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Les cartogrammes</span></span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./2000_references.html" class="sidebar-item-text sidebar-link">
Expand All @@ -168,23 +202,17 @@
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="true">
<span class="menu-text">Appendices</span></a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true" aria-label="Basculer la section">
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="true" aria-label="Basculer la section">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./05_anamorphoses.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">A</span>&nbsp; <span class="chapter-title">Les cartogrammes</span></span></a>
</div>
</li>
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./2002_data.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">B</span>&nbsp; <span class="chapter-title">Les données du projet</span></span></a>
<span class="menu-text"><span class="chapter-number">A</span>&nbsp; <span class="chapter-title">Les données du projet</span></span></a>
</div>
</li>
</ul>
Expand Down
Loading

0 comments on commit 6d2868e

Please sign in to comment.