diff --git a/01-introduction.ipynb b/01-introduction.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..862a0be21559b7af8e2f75560c038e8540b7dfd9 --- /dev/null +++ b/01-introduction.ipynb @@ -0,0 +1,71 @@ +{ + "cells": [ + { + "cell_type": "raw", + "metadata": {}, + "source": [ + "---\n", + "bibliography: references.bib\n", + "---" + ], + "id": "a9a187e6" + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Introduction {#introductionx}\n", + "\n", + "## Spatial in R : History and evolutions\n", + "\n", + "Historically, 4 packages make it possible to import, manipulate and transform spatial data:\n", + "\n", + "- The package `rgdal` [@rgdal] which is an interface between Rand the [GDAL](http://www.gdal.org/) [@GDAL] and [PROJ](https://proj.org/) [@PROJ] libraries allow you to import and export spatial data (shapefiles for example) and also to manage cartographic projections\\\n", + "- The package `sp` [@sp] provides class and methods for vector spatial data in R. It allows displaying background maps, inspectiong an attribute table etc.\\\n", + "- The package `rgeos` [@rgeos] gives access to the [GEOS](http://trac.osgeo.org/geos/) spatial operations library and therefore makes classic GIS operations available: calculation of surfaces or perimeters, calculation of distances, spatial aggregations, buffer zones, intersections, etc.\\\n", + "- The package `raster` [@raster] is dedicated to the import, manipulation and modeling of raster data.\n", + "\n", + "Today, the main developments concerning vector data have moved away from the old 3 (`sp`, `rgdal`, `rgeos`) to rely mainly on the package `sf` ([@sf], [@pebesma2018]). In this manual we will rely exclusively on this package to manipulate vector data.\n", + "\n", + "The packages `stars` [@stars] and `terra` [@terra] come to replace the package `raster` for processing raster data. We have chosen to use the package here `terra` for its proximity to the `raster`.\n", + "\n", + "## The package `sf`\n", + "\n", + "<img src=\"img/sf.gif\" align=\"right\" width=\"150\"/> The package `sf` was released in late 2016 by Edzer Pebesma (also author of `sp`). Its goal is to combine the feature of `sp`, `rgeos` and `rgdal` in a single, more ergonomic package. This package offers simple objects (following the [*simple feature*](https://en.wikipedia.org/wiki/Simple_Features) standard) which are easier to manipulate. Particular attention has been paid to the compatibility of the package with the *pipe* syntax and the operators of the `tidyverse`.\n", + "\n", + "`sf` directly uses the GDAL, GEOS and PROJ libraries.\n", + "\n", + "{fig-align=\"center\" width=\"600\"}\n", + "\n", + "[From r-spatial.org](https://r-spatial.org/r/2020/03/17/wkt.html)\n", + "\n", + "::: {.callout-note icon=\"false\"}\n", + "Website of package `sf` :\n", + "\n", + "[Simple Features for R](https://r-spatial.github.io/sf/)\n", + ":::\n", + "\n", + "### Format of spatial objects `sf`\n", + "\n", + "{fig-align=\"center\" width=\"600\"}\n", + "\n", + "Objects`sf` are objects in `data.frame` which one of the columns contains geometries. This column is the class of sfc (*simple feature column*) and each individual of the column is a sfg (*simple feature geometry)*. This format is very practical insofa as the data and the geometries are intrinsically linked in the same object.\n", + "\n", + "```{block2, type='linky'}\n", + "Thumbnail describing the simple feature format: \n", + " [Simple Features for R](https://r-spatial.github.io/sf/articles/sf1.html)\n", + "```\n" + ], + "id": "b4f55113" + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/01-introduction.qmd b/01-introduction.qmd new file mode 100644 index 0000000000000000000000000000000000000000..627c16e39356900b0e3b00f62d60d3dc7d725543 --- /dev/null +++ b/01-introduction.qmd @@ -0,0 +1,89 @@ +--- +bibliography: references.bib +--- + +# Introduction {#introductionx} + +## Spatial in R : History and evolutions + +Historically, 4 packages make it possible to import, manipulate and transform spatial data: + +- The package `rgdal` [@rgdal] which is an interface between R and the [GDAL](http://www.gdal.org/) [@GDAL] and [PROJ](https://proj.org/) [@PROJ] libraries allow you to import and export spatial data (shapefiles for example) and also to manage cartographic projections\ +- The package `sp` [@sp] provides class and methods for vector spatial data in R. It allows displaying background maps, inspectiong an attribute table etc.\ +- The package `rgeos` [@rgeos] gives access to the [GEOS](http://trac.osgeo.org/geos/) spatial operations library and therefore makes classic GIS operations available: calculation of surfaces or perimeters, calculation of distances, spatial aggregations, buffer zones, intersections, etc.\ +- The package `raster` [@raster] is dedicated to the import, manipulation and modeling of raster data. + +Today, the main developments concerning vector data have moved away from the old 3 (`sp`, `rgdal`, `rgeos`) to rely mainly on the package `sf` ([@sf], [@pebesma2018]). In this manual we will rely exclusively on this package to manipulate vector data. + +The packages `stars` [@stars] and `terra` [@terra] come to replace the package `raster` for processing raster data. We have chosen to use the package here `terra` for its proximity to the `raster`. + +## The package `sf` + +<img src="img/sf.gif" align="right" width="150"/> The package `sf` was released in late 2016 by Edzer Pebesma (also author of `sp`). Its goal is to combine the feature of `sp`, `rgeos` and `rgdal` in a single, more ergonomic package. This package offers simple objects (following the [*simple feature*](https://en.wikipedia.org/wiki/Simple_Features) standard) which are easier to manipulate. Particular attention has been paid to the compatibility of the package with the *pipe* syntax and the operators of the `tidyverse`. + +`sf` directly uses the GDAL, GEOS and PROJ libraries. + +{fig-align="center" width="600"} + +[From r-spatial.org](https://r-spatial.org/r/2020/03/17/wkt.html) + +::: {.callout-note appearance="minimal" icon="false"} +Website of package `sf` : + +[Simple Features for R](https://r-spatial.github.io/sf/) +::: + +### Format of spatial objects `sf` + +{fig-align="center" width="600"} + +Objects`sf` are objects in `data.frame` which one of the columns contains geometries. This column is the class of sfc (*simple feature column*) and each individual of the column is a sfg *(simple feature geometry)*. This format is very practical insofa as the data and the geometries are intrinsically linked in the same object. + +::: {.callout-note appearance="minimal" icon="false"} +Thumbnail describing the simple feature format: + +[Simple Features for R](https://r-spatial.github.io/sf/articles/sf1.html) +::: + +::: callout-tip +A benchmark of vector processing libraries is available [here](https://github.com/kadyb/vector-benchmark). +::: + +## Package `mapsf` + +The free R software spatial ecosystem is rich, dynamic and mature and several packages allow to import, process and represent spatial data. The package [`mapsf`](https://CRAN.R-project.org/package=maps) [@mapsf] relies on this ecosystem to integrate the creation of quality thematic maps into processing chains with R. + +Other packages can be used to make thematic maps. The package `ggplot2` [@ggplot2], in association with the package `ggspatial` [@ggspatial], allows for example to display spatial objects and to make simple thematic maps. The package `tmap` [@tmap] is dedicated to the creation of thematic maps, it uses a syntax close to that of `ggplot2` (sequence of instructions combined with the '+' sign). Documentation and tutorials for using these two packages are readily available on the web. + +Here, we will mainly use the package `mapsf` whose functionalities are quite complete and the handling rather simple. In addition, the package is relatively light. + +<img src="img/logo_mapsf.png" align="right" width="120"/> + +`mapsf` allows you to create most of the types of map usually used in statistical cartography (choropleth maps, typologies, proportional or graduated symbols, etc.). For each type of map, several parameters are used to customize the cartographic representation. These parameters are the same as those found in the usual GIS or cartography software (for example, the choice of discretizations and color palettes, the modification of the size of the symbols or the customization of the legends). Associated with the data representation functions, other functions are dedicated to cartographic dressing (themes or graphic charters, legends, scales, orientation arrows, title, credits, annotations, etc.), the creation of boxes or the exporting maps.\ +`mapsf` is the successor of [`cartography`](http://riatelab.github.io/cartography/docs/) [@cartography], it offers the same main functionalities while being lighter and more ergonomic. + +To use this package several sources can be consulted: + +- The package documentation accessible [on the internet](http://riatelab.github.io/mapsf/) or directly in R (`?mapsf`), + +- A [*cheat sheet*](https://raw.githubusercontent.com/riatelab/mapsf/master/vignettes/web_only/img/mapsf_cheatsheet.pdf), + +{fig-align="center" width="600"} + +- The [vignettes](https://riatelab.github.io/mapsf/articles/) associated with the package show sample scripts, + +- The [R Geomatics](https://rgeomatic.hypotheses.org/) blog which provides resources and examples related to the package and more generally to the R spatial ecosystem. + +## The package `terra` + +<img src="img/logo_terra.png" align="right" width="150"/> The package `terra` was release in early 2020 by Robert J. Hijmans (also author of `raster`). Its objective is to propose methods of treatment and analysis of raster data. This package is very similar to the package `raster`; but it has more features, it's easier to use, and it's faster. + +::: {.callout-note appearance="minimal" icon="false"} +Website of package `terra` : + +[Spatial Data Science with R and "terra"](https://rspatial.org/terra/) +::: + +::: callout-tip +A benchmark of raster processing libraries is available [here](https://github.com/kadyb/raster-benchmark). +::: diff --git a/_quarto.yml b/_quarto.yml index 30d67c41cf7b023e1cbc6587d8b1f0485543600d..5bd9928f7b64d93e0a531df61875d166cf7c6a1b 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -12,10 +12,15 @@ book: {height="50"} chapters: - index.qmd + - 01-introduction.qmd + - references.qmd + +bibliography: references.bib format: html: theme: cosmo + css: styles.css cover-image: img/geohealth_banner.jpeg link-external-newwindow: true diff --git a/img/logo_mapsf.png b/img/logo_mapsf.png new file mode 100644 index 0000000000000000000000000000000000000000..3b608788fbd24f9d6a7ad83eaa87602c0fcdf2bf Binary files /dev/null and b/img/logo_mapsf.png differ diff --git a/img/logo_terra.png b/img/logo_terra.png new file mode 100644 index 0000000000000000000000000000000000000000..0b8c94d8cebb76eeb2ee58961d1e43b08d6bea58 Binary files /dev/null and b/img/logo_terra.png differ diff --git a/img/mapsf_cheatsheet.png b/img/mapsf_cheatsheet.png new file mode 100644 index 0000000000000000000000000000000000000000..4d3102f112340c4c3643b6f3157094f16219f305 Binary files /dev/null and b/img/mapsf_cheatsheet.png differ diff --git a/img/sf.gif b/img/sf.gif new file mode 100644 index 0000000000000000000000000000000000000000..4f789aabbc87dc252ce48f345b945a3aaa32a535 Binary files /dev/null and b/img/sf.gif differ diff --git a/img/sf.png b/img/sf.png new file mode 100644 index 0000000000000000000000000000000000000000..f6731e25f88e25866d0d12a8cb37a50e79e60266 Binary files /dev/null and b/img/sf.png differ diff --git a/img/sf_deps.png b/img/sf_deps.png new file mode 100644 index 0000000000000000000000000000000000000000..add75b53e08ffd7a2a6cab239916644dd4155b82 Binary files /dev/null and b/img/sf_deps.png differ diff --git a/public/site_libs/bootstrap/bootstrap.min.css b/public/site_libs/bootstrap/bootstrap.min.css index 3838b4c9d307e8841406664a7a8ab3a7101a47f0..33e11d0126e7a70bce28786ec835924dd542edec 100644 --- a/public/site_libs/bootstrap/bootstrap.min.css +++ b/public/site_libs/bootstrap/bootstrap.min.css @@ -1,4 +1,4 @@ -/*! +/*! * Bootstrap v5.1.3 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. diff --git a/references.bib b/references.bib new file mode 100644 index 0000000000000000000000000000000000000000..94df4dc7dfc0e89874606349f2e506a7527ee72b --- /dev/null +++ b/references.bib @@ -0,0 +1,244 @@ +@article{tidygeocoder, + title = {tidygeocoder: An R package for geocoding}, + author = {Cambon, Jesse and {Hernangómez}, Diego and Belanger, Christopher and Possenriede, Daniel}, + year = {2021}, + date = {2021}, + pages = {3544}, + volume = {6}, + doi = {10.21105/joss.03544}, + url = {https://doi.org/10.21105/joss.03544} +} + +@article{banR, + title = {banR: R Client for the BAN API}, + author = {Gombin, Joel and Chevalier, Paul-Antoine}, + year = {2022}, + date = {2022} +} + +@article{maptiles, + title = {maptiles: Download and Display Map Tiles}, + author = {Giraud, {Timothée}}, + year = {2021}, + date = {2021}, + url = {https://CRAN.R-project.org/package=maptiles} +} + +@article{mapedit, + title = {mapedit: Interactive Editing of Spatial Data in R}, + author = {Appelhans, Tim and Russell, Kenton and Busetto, Lorenzo}, + year = {2020}, + date = {2020}, + url = {https://CRAN.R-project.org/package=mapedit} +} + +@article{mapsf, + title = {mapsf: Thematic Cartography}, + author = {Giraud, {Timothée}}, + year = {2022}, + date = {2022}, + url = {https://CRAN.R-project.org/package=mapsf} +} + +@article{linemap, + title = {linemap: Line Maps}, + author = {Giraud, {Timothée}}, + year = {2021}, + date = {2021}, + url = {https://CRAN.R-project.org/package=linemap} +} + +@article{tanaka, + title = {tanaka: Design Shaded Contour Lines (or Tanaka) Maps}, + author = {Giraud, {Timothée}}, + year = {2022}, + date = {2022}, + url = {https://CRAN.R-project.org/package=tanaka} +} + +@article{tanaka1950, + title = {The Relief Contour Method of Representing Topography on Maps}, + author = {Tanaka, Kitiro}, + year = {1950}, + month = {07}, + date = {1950-07}, + journal = {Geographical Review}, + pages = {444}, + volume = {40}, + number = {3}, + doi = {10.2307/211219}, + url = {http://dx.doi.org/10.2307/211219} +} + +@article{leaflet, + title = {leaflet: Create Interactive Web Maps with the JavaScript 'Leaflet' +Library}, + author = {Cheng, Joe and Karambelkar, Bhaskar and Xie, Yihui}, + year = {2022}, + date = {2022}, + url = {https://CRAN.R-project.org/package=leaflet} +} + +@article{mapview, + title = {mapview: Interactive Viewing of Spatial Data in R}, + author = {Appelhans, Tim and Detsch, Florian and Reudenbach, Christoph and Woellauer, Stefan}, + year = {2022}, + date = {2022}, + url = {https://CRAN.R-project.org/package=mapview} +} + + +@misc{JS-Leaflet, + title={Leaflet javascript libary}, + author={Agafonkin, Vladimir}, + year={2015} +} + +@article{maptiles-2, + title = {maptiles: Download and Display Map Tiles}, + author = {Giraud, {Timothée}}, + year = {2021}, + date = {2021}, + url = {https://CRAN.R-project.org/package=maptiles} +} + +@article{osmdata, + title = {osmdata}, + author = {Padgham, Mark and Rudis, Bob and Lovelace, Robin and Salmon, {Maëlle}}, + year = {2017}, + date = {2017}, + volume = {2}, + doi = {10.21105/joss.00305}, + url = {https://doi.org/10.21105/joss.00305} +} + +@article{osmextract, + title = {osmextract: Download and Import Open Street Map Data Extracts}, + author = {Gilardi, Andrea and Lovelace, Robin}, + year = {2021}, + date = {2021}, + url = {https://CRAN.R-project.org/package=osmextract} +} + +@article{rgdal, + title = {rgdal: Bindings for the 'Geospatial' Data Abstraction Library}, + author = {Bivand, Roger and Keitt, Tim and Rowlingson, Barry}, + year = {2022}, + date = {2022}, + url = {https://CRAN.R-project.org/package=rgdal} +} + +@article{sp, + title = {Classes and methods for spatial data in {\textbraceleft}R{\textbraceright}}, + author = {Pebesma, Edzer J. and Bivand, Roger S.}, + year = {2005}, + date = {2005}, + volume = {5}, + url = {https://CRAN.R-project.org/doc/Rnews/} +} + +@article{rgeos, + title = {rgeos: Interface to Geometry Engine - Open Source ('GEOS')}, + author = {Bivand, Roger and Rundel, Colin}, + year = {2021}, + date = {2021}, + url = {https://CRAN.R-project.org/package=rgeos} +} + +@article{raster, + title = {raster: Geographic Data Analysis and Modeling}, + author = {Hijmans, Robert J.}, + year = {2022}, + date = {2022}, + url = {https://CRAN.R-project.org/package=raster} +} + +@article{sf, + title = {{\textbraceleft}Simple Features for R: Standardized Support for Spatial Vector Data{\textbraceright}}, + author = {Pebesma, Edzer}, + year = {2018}, + date = {2018}, + volume = {10}, + doi = {10.32614/RJ-2018-009}, + url = {https://doi.org/10.32614/RJ-2018-009} +} + +@article{stars, + title = {stars: Spatiotemporal Arrays, Raster and Vector Data Cubes}, + author = {Pebesma, Edzer}, + year = {2021}, + date = {2021}, + url = {https://CRAN.R-project.org/package=stars} +} + +@article{terra, + title = {terra: Spatial Data Analysis}, + author = {Hijmans, Robert J.}, + year = {2022}, + date = {2022}, + url = {https://CRAN.R-project.org/package=terra} +} + +@article{ggspatial, + title = {ggspatial: Spatial Data Framework for ggplot2}, + author = {Dunnington, Dewey}, + year = {2021}, + date = {2021}, + url = {https://CRAN.R-project.org/package=ggspatial} +} + +@article{cartography, + title = {cartography: Create and Integrate Maps in your R Workflow}, + author = {Giraud, {Timothée} and Lambert, Nicolas}, + year = {2016}, + date = {2016}, + volume = {1}, + doi = {10.21105/joss.00054}, + url = {http://dx.doi.org/10.21105/joss.00054} +} + +@article{ggplot2, + title = {ggplot2: Elegant Graphics for Data Analysis}, + author = {Wickham, Hadley}, + year = {2016}, + date = {2016}, + url = {https://ggplot2.tidyverse.org} +} + +@article{tmap, + title = {{\textbraceleft}tmap{\textbraceright}: Thematic Maps in {\textbraceleft}R{\textbraceright}}, + author = {Tennekes, Martijn}, + year = {2018}, + date = {2018}, + volume = {84}, + doi = {10.18637/jss.v084.i06} +} + +@article{pebesma2018, + title = {Simple Features for R: Standardized Support for Spatial Vector Data}, + author = {Pebesma, Edzer}, + year = {2018}, + date = {2018}, + journal = {The R Journal}, + pages = {439}, + volume = {10}, + number = {1}, + doi = {10.32614/rj-2018-009}, + url = {http://dx.doi.org/10.32614/RJ-2018-009}, + langid = {en} +} + +@Manual{GDAL, + title = {{GDAL/OGR} Geospatial Data Abstraction software Library}, + author = {{GDAL/OGR contributors}}, + organization = {Open Source Geospatial Foundation}, + url = {https://gdal.org}, +} + +@Manual{PROJ, + title = {{PROJ} coordinate transformation software library}, + author = {{PROJ contributors}}, + organization = {Open Source Geospatial Foundation}, + year = {2021}, + url = {https://proj.org/}, +} \ No newline at end of file diff --git a/references.qmd b/references.qmd new file mode 100644 index 0000000000000000000000000000000000000000..925f7c49464a373543ab18c1dbcb9d3ebeceabbf --- /dev/null +++ b/references.qmd @@ -0,0 +1,4 @@ +# References {.unnumbered} + +::: {#refs} +::: diff --git a/rspatial-for-onehealth b/rspatial-for-onehealth.Rproj similarity index 100% rename from rspatial-for-onehealth rename to rspatial-for-onehealth.Rproj diff --git a/styles.css b/styles.css new file mode 100644 index 0000000000000000000000000000000000000000..9ff4a37dfceaa70ed37b186504870793c15ccc6b --- /dev/null +++ b/styles.css @@ -0,0 +1,4 @@ +.code-out { + background-color: #f0f2f4; + font-weight: bold; +} \ No newline at end of file