Skip to content
Snippets Groups Projects
Commit 74607a99 authored by lea.douchet_ird.fr's avatar lea.douchet_ird.fr
Browse files

merging

parents 098e94b7 6e4a1a00
No related branches found
No related tags found
No related merge requests found
Pipeline #1064 passed
...@@ -49,3 +49,6 @@ examples ...@@ -49,3 +49,6 @@ examples
.quarto/ .quarto/
/.quarto/ /.quarto/
*.osm.pbf
data_cambodia/geofabrik_cambodia-latest.gpkg
...@@ -31,6 +31,29 @@ The packages `stars` [@stars] and `terra` [@terra] come to replace the package ` ...@@ -31,6 +31,29 @@ The packages `stars` [@stars] and `terra` [@terra] come to replace the package `
Website of package `sf` : [Simple Features for R](https://r-spatial.github.io/sf/) Website of package `sf` : [Simple Features for R](https://r-spatial.github.io/sf/)
::: :::
Many of the spatial data available on the internet are in shapefile format, which can be opened in the following way
```{r class.output="code-out"}
library(sf)
district <- st_read("data_cambodia/district.shp")
```
::: callout-important
## Shapefile format limitations
For the multiple limitations of this format (multi-file, limited number of records...) we advise you to prefer another format such as the geopackage `*.gpkg`. All the good reasons not to use the shapefile are [here](http://switchfromshapefile.org/).
:::
A geopackage is a database, to load a layer, you must know its name
```{r class.output="code-out"}
st_layers("data_cambodia/cambodia.gpkg")
```
```{r class.output="code-out"}
road <- st_read("data_cambodia/cambodia.gpkg", layer = "road")
```
### Format of spatial objects `sf` ### Format of spatial objects `sf`
![](img/sf.png){fig-align="center" width="600"} ![](img/sf.png){fig-align="center" width="600"}
......
...@@ -4,8 +4,35 @@ bibliography: references.bib ...@@ -4,8 +4,35 @@ bibliography: references.bib
# Data Acquisition # Data Acquisition
All the data needed to complete this training can be retrieved at [this link](https://e1.pcloud.link/publink/show?code=XZQ60YZxwN09vWJ8bmuSivWezhuG8u94lCV).
## Online databases ## Online databases
### On global scale
Since the appearance of the `sf` package, which has greatly contributed to the popularization of spatial data manipulation with R, many packages for making geographic data (geometries and/or attributes) available have been developed. Most of them are API packages that allow to query data made available on the Web, directly with R. This chapter presents a non-exhaustive list of them.
- <img src="img/geom.svg" alt="Geometries" width="20"/> `rnaturalearth` [@R-rnaturalearth]: retrieves [Natural Earth map data](https://www.naturalearthdata.com/).\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `gadmr` [@R-gadmr]: retrieves data from the [GADM](https://gadm.org/index.html) (national and sub-national administrative divisions of all countries in the world).\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `rgeoboundaries` [@R-rgeoboundaries] : R client for the [geoBoundaries API](https://www.geoboundaries.org/index.html), providing political administrative boundaries of countries.
- <img src="img/geom.svg" alt="Geometries" width="20"/> `cshapes` [@R-cshapes]: makes available national boundaries, from 1886 to present.\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `osmextract` [@R-osmextract]: allows importing [OpenStreetMap data](https://www.openstreetmap.org/).
- <img src="img/geom.svg" alt="Geometries" width="20"/> `osmdata` [@osmdata2017]: to download and use OpenStreetMap data.\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `maptiles` [@R-maptiles] : This package downloads, composes and displays tiles from a large number of providers (*OpenStreetMap*, *Stamen*, *Esri*, *CARTO* or *Thunderforest*).\
- <img src="img/table.svg" alt="attribute data" width="20"/> `geonames` [@R-geonames] : allows you to query the [geonames DB](http://www.geonames.org/), which provides locations in particular.
- <img src="img/table.svg" alt="attribute data" width="20"/> `wbstats` [@wbstats2020] and `WDI` [@R-WDI]: provide access to World Bank data and statistics.\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `sen2r` [@R-sen2r]: allows automatic download and preprocessing of Sentinel-2 satellite data.\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `MODIStsp` [@MODIStsp2016]: find, download and process *MODIS* images.\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `geodata` [@R-geodata]: provides access to [data](https://github.com/rspatial/geodata) on climate, elevation, soil, species occurrence and administrative boundaries.\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `elevatr` [@R-elevatr]: provides access to elevation data made available by [*Amazon Web Services Terrain Tiles*](https://registry.opendata.aws/terrain-tiles/), the [*Open Topography Global Datasets API*](https://opentopography.org/developers/) and the [*USGS Elevation Point Query Service*](https://nationalmap.gov/epqs/).
- <img src="img/geom.svg" alt="Geometries" width="20"/> `rgee` [@R-rgee]: allows use of the [Google Earth Engine](https://www.google.com/intl/fr_in/earth/education/tools/google-earth-engine/) API, a public data catalog and computational infrastructure for satellite images.\
- <img src="img/geom.svg" alt="Geometries" width="20"/> `nasapower` [@nasapower2018]: *NASA* client API (global energy resource forecasting, meteorology, surface solar energy, and climatology).
- <img src="img/geom.svg" alt="Geometries" width="20"/> `geoknife` [@geoknife2015]: allows processing (online) of large raster data from the *Geo Data Portal* of the *U.S. Geological Survey*.\
- <img src="img/table.svg" alt="attribute data" width="20"/> `wopr` [@R-wopr]: provides API access to the [*WorldPop Open Population Repository*](https://wopr.worldpop.org/) database.\
- <img src="img/geom.svg" alt="Geometries" width="20"/> <img src="img/table.svg" alt="attribute data" width="20"/> `rdhs` [@rdhs2019] : [Demographic and Health Survey (DHS) client API and data managements](https://dhsprogram.com/).
Several data sets are referenced by the ESoR (Environnement, Societies and Health Risk) research group [here](https://www.netvibes.com/geohealth?page=geohealth#Online_databases)
## OpenStreetMap ## OpenStreetMap
::: {style="float: right"} ::: {style="float: right"}
...@@ -111,7 +138,6 @@ The result contains a point layer and a polygon layer. The polygon layer contain ...@@ -111,7 +138,6 @@ The result contains a point layer and a polygon layer. The polygon layer contain
sf_use_s2(FALSE) sf_use_s2(FALSE)
``` ```
```{r osmdata2, class.output="code-out", warning=FALSE, message=FALSE} ```{r osmdata2, class.output="code-out", warning=FALSE, message=FALSE}
hospital_point <- hospital$osm_points hospital_point <- hospital$osm_points
hospital_poly <- hospital$osm_polygons #Extracting centroids of polygons hospital_poly <- hospital$osm_polygons #Extracting centroids of polygons
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="generator" content="quarto-1.1.189"> <meta name="generator" content="quarto-1.1.251">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
...@@ -20,6 +20,69 @@ ul.task-list li input[type="checkbox"] { ...@@ -20,6 +20,69 @@ ul.task-list li input[type="checkbox"] {
margin: 0 0.8em 0.2em -1.6em; margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle; vertical-align: middle;
} }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
div.csl-bib-body { } div.csl-bib-body { }
div.csl-entry { div.csl-entry {
clear: both; clear: both;
...@@ -235,6 +298,65 @@ div.csl-indent { ...@@ -235,6 +298,65 @@ div.csl-indent {
</div> </div>
</div> </div>
</div> </div>
<p>Many of the spatial data available on the internet are in shapefile format, which can be opened in the following way</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(sf)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Linking to GEOS 3.10.2, GDAL 3.4.3, PROJ 8.2.1; sf_use_s2() is TRUE</code></pre>
</div>
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>district <span class="ot">&lt;-</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/district.shp"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre class="code-out"><code>Reading layer `district' from data source
`/home/lucas/Documents/ForgeIRD/rspatial-for-onehealth/data_cambodia/district.shp'
using driver `ESRI Shapefile'
Simple feature collection with 197 features and 10 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 211534.7 ymin: 1149105 xmax: 784612.1 ymax: 1625495
Projected CRS: WGS 84 / UTM zone 48N</code></pre>
</div>
</div>
<div class="callout-important callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Shapefile format limitations
</div>
</div>
<div class="callout-body-container callout-body">
<p>For the multiple limitations of this format (multi-file, limited number of records…) we advise you to prefer another format such as the geopackage <code>*.gpkg</code>. All the good reasons not to use the shapefile are <a href="http://switchfromshapefile.org/">here</a>.</p>
</div>
</div>
<p>A geopackage is a database, to load a layer, you must know its name</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">st_layers</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre class="code-out"><code>Driver: GPKG
Available layers:
layer_name geometry_type features fields crs_name
1 country Multi Polygon 1 10 WGS 84 / UTM zone 48N
2 district Multi Polygon 197 10 WGS 84 / UTM zone 48N
3 education Multi Polygon 25 19 WGS 84 / UTM zone 48N
4 hospital Point 956 13 WGS 84 / UTM zone 48N
5 cases Multi Point 972 2 WGS 84 / UTM zone 48N
6 road Multi Line String 6 9 WGS 84 / UTM zone 48N</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>road <span class="ot">&lt;-</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"road"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre class="code-out"><code>Reading layer `road' from data source
`/home/lucas/Documents/ForgeIRD/rspatial-for-onehealth/data_cambodia/cambodia.gpkg'
using driver `GPKG'
Simple feature collection with 6 features and 9 fields
Geometry type: MULTILINESTRING
Dimension: XY
Bounding box: xmin: 212377 ymin: 1152214 xmax: 784654.7 ymax: 1625281
Projected CRS: WGS 84 / UTM zone 48N</code></pre>
</div>
</div>
<section id="format-of-spatial-objects-sf" class="level3" data-number="1.2.1"> <section id="format-of-spatial-objects-sf" class="level3" data-number="1.2.1">
<h3 data-number="1.2.1" class="anchored" data-anchor-id="format-of-spatial-objects-sf"><span class="header-section-number">1.2.1</span> Format of spatial objects <code>sf</code></h3> <h3 data-number="1.2.1" class="anchored" data-anchor-id="format-of-spatial-objects-sf"><span class="header-section-number">1.2.1</span> Format of spatial objects <code>sf</code></h3>
<div class="quarto-figure quarto-figure-center"> <div class="quarto-figure quarto-figure-center">
......
This diff is collapsed.
public/02-data_acquisition_files/figure-html/display_point-1.png

1.11 MiB | W: | H:

public/02-data_acquisition_files/figure-html/display_point-1.png

1.11 MiB | W: | H:

public/02-data_acquisition_files/figure-html/display_point-1.png
public/02-data_acquisition_files/figure-html/display_point-1.png
public/02-data_acquisition_files/figure-html/display_point-1.png
public/02-data_acquisition_files/figure-html/display_point-1.png
  • 2-up
  • Swipe
  • Onion skin
public/03-vector_data_files/figure-html/osrmroute-1.png

231 KiB | W: | H:

public/03-vector_data_files/figure-html/osrmroute-1.png

231 KiB | W: | H:

public/03-vector_data_files/figure-html/osrmroute-1.png
public/03-vector_data_files/figure-html/osrmroute-1.png
public/03-vector_data_files/figure-html/osrmroute-1.png
public/03-vector_data_files/figure-html/osrmroute-1.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -874,4 +874,4 @@ window.document.addEventListener("DOMContentLoaded", function (event) { ...@@ -874,4 +874,4 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
<script src="site_libs/quarto-html/zenscroll-min.js"></script> <script src="site_libs/quarto-html/zenscroll-min.js"></script>
</body></html> </body></html>
\ No newline at end of file
public/07-basic_statistics_files/figure-html/MoransI-1.png

16.7 KiB | W: | H:

public/07-basic_statistics_files/figure-html/MoransI-1.png

16.5 KiB | W: | H:

public/07-basic_statistics_files/figure-html/MoransI-1.png
public/07-basic_statistics_files/figure-html/MoransI-1.png
public/07-basic_statistics_files/figure-html/MoransI-1.png
public/07-basic_statistics_files/figure-html/MoransI-1.png
  • 2-up
  • Swipe
  • Onion skin
public/07-basic_statistics_files/figure-html/inc_visualization-1.png

52.4 KiB | W: | H:

public/07-basic_statistics_files/figure-html/inc_visualization-1.png

349 KiB | W: | H:

public/07-basic_statistics_files/figure-html/inc_visualization-1.png
public/07-basic_statistics_files/figure-html/inc_visualization-1.png
public/07-basic_statistics_files/figure-html/inc_visualization-1.png
public/07-basic_statistics_files/figure-html/inc_visualization-1.png
  • 2-up
  • Swipe
  • Onion skin
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="globe-americas" class="svg-inline--fa fa-globe-americas fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><path fill="currentColor" d="M248 8C111.03 8 0 119.03 0 256s111.03 248 248 248 248-111.03 248-248S384.97 8 248 8zm82.29 357.6c-3.9 3.88-7.99 7.95-11.31 11.28-2.99 3-5.1 6.7-6.17 10.71-1.51 5.66-2.73 11.38-4.77 16.87l-17.39 46.85c-13.76 3-28 4.69-42.65 4.69v-27.38c1.69-12.62-7.64-36.26-22.63-51.25-6-6-9.37-14.14-9.37-22.63v-32.01c0-11.64-6.27-22.34-16.46-27.97-14.37-7.95-34.81-19.06-48.81-26.11-11.48-5.78-22.1-13.14-31.65-21.75l-.8-.72a114.792 114.792 0 0 1-18.06-20.74c-9.38-13.77-24.66-36.42-34.59-51.14 20.47-45.5 57.36-82.04 103.2-101.89l24.01 12.01C203.48 89.74 216 82.01 216 70.11v-11.3c7.99-1.29 16.12-2.11 24.39-2.42l28.3 28.3c6.25 6.25 6.25 16.38 0 22.63L264 112l-10.34 10.34c-3.12 3.12-3.12 8.19 0 11.31l4.69 4.69c3.12 3.12 3.12 8.19 0 11.31l-8 8a8.008 8.008 0 0 1-5.66 2.34h-8.99c-2.08 0-4.08.81-5.58 2.27l-9.92 9.65a8.008 8.008 0 0 0-1.58 9.31l15.59 31.19c2.66 5.32-1.21 11.58-7.15 11.58h-5.64c-1.93 0-3.79-.7-5.24-1.96l-9.28-8.06a16.017 16.017 0 0 0-15.55-3.1l-31.17 10.39a11.95 11.95 0 0 0-8.17 11.34c0 4.53 2.56 8.66 6.61 10.69l11.08 5.54c9.41 4.71 19.79 7.16 30.31 7.16s22.59 27.29 32 32h66.75c8.49 0 16.62 3.37 22.63 9.37l13.69 13.69a30.503 30.503 0 0 1 8.93 21.57 46.536 46.536 0 0 1-13.72 32.98zM417 274.25c-5.79-1.45-10.84-5-14.15-9.97l-17.98-26.97a23.97 23.97 0 0 1 0-26.62l19.59-29.38c2.32-3.47 5.5-6.29 9.24-8.15l12.98-6.49C440.2 193.59 448 223.87 448 256c0 8.67-.74 17.16-1.82 25.54L417 274.25z"></path></svg>
\ No newline at end of file
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="table" class="svg-inline--fa fa-table fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M464 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V80c0-26.51-21.49-48-48-48zM224 416H64v-96h160v96zm0-160H64v-96h160v96zm224 160H288v-96h160v96zm0-160H288v-96h160v96z"></path></svg>
\ No newline at end of file
This diff is collapsed.
...@@ -435,4 +435,12 @@ Library}, ...@@ -435,4 +435,12 @@ Library},
number={25}, number={25},
pages={515}, pages={515},
year={2018} year={2018}
}
@article{rnaturalearth,
title = {rnaturalearth: World Map Data from Natural Earth},
author = {South, Andy},
year = {2017},
date = {2017},
url = {https://CRAN.R-project.org/package=rnaturalearth}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment