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

merge

parents ff30d4c0 40c80dd1
No related branches found
No related tags found
No related merge requests found
Pipeline #1056 passed
Showing
with 43 additions and 42 deletions
......@@ -4,37 +4,6 @@ bibliography: references.bib
# Data Acquisition
## Import from lat / long file
The function `st_as_sf()` makes it possible to transform a `data.frame` container of geographic coordinates into an object `sf`. Here we use the `data.frame` `places2` created in the previous point.
```{r build_sf, eval = TRUE, echo = TRUE, nm = TRUE, fig.width=8, class.output="code-out", warning=FALSE, message=FALSE}
library(sf)
place_sf <- st_as_sf(read.csv("data_cambodia/adress.csv"), coords = c("long", "lat"), crs = 4326)
place_sf
```
```{r echo=FALSE, eval=TRUE}
sf_use_s2(FALSE)
```
To create a `sf` POINT type object with only one pair of coordinate (WGS84, longitude=0.5, latitude = 45.5) :
```{r build_sf2, eval = TRUE, echo = TRUE, nm = TRUE, fig.width=8, class.output="code-out", warning=FALSE, message=FALSE}
library(sf)
test_point <- st_as_sf(data.frame(x = 0.5, y = 45.5), coords = c("x", "y"), crs = 4326)
test_point
```
We can display this object `sf` on an [OpenStreetMap](https://www.openstreetmap.org/) basesmap with the package maptiles `maptiles` [@maptiles].
```{r display_sf, eval = TRUE, echo = TRUE, nm = TRUE, out.width="788px", warning=FALSE, message=FALSE}
library(maptiles)
osm <- get_tiles(x = place_sf, zoom = 12)
plot_tiles(osm)
plot(st_geometry(place_sf), pch = 2, cex = 2, col = "red", add = TRUE)
```
## Online databases
## OpenStreetMap
......@@ -136,7 +105,12 @@ hospital <- osmdata_sf(query)
hospital <- unique_osmdata(hospital) #Result reduction (points composing polygon are detected)
```
The result contains a point layer and a polygon layer. The polygon layer contains polygons that represent fast food-food place. To obtain a coherent point layer we can use the centroids of the polygons.
The result contains a point layer and a polygon layer. The polygon layer contains polygons that represent hospitals. To obtain a coherent point layer we can use the centroids of the polygons.
```{r echo=FALSE, eval=TRUE, warning=FALSE, error=FALSE}
sf_use_s2(FALSE)
```
```{r osmdata2, class.output="code-out", warning=FALSE, message=FALSE}
hospital_point <- hospital$osm_points
......@@ -213,6 +187,37 @@ roads <- oe_get(
mf_map(x = roads)
```
## Import from lat / long file
The function `st_as_sf()` makes it possible to transform a `data.frame` container of geographic coordinates into an object `sf`. Here we use the `data.frame` `places2` created in the previous point.
```{r build_sf, eval = TRUE, echo = TRUE, nm = TRUE, fig.width=8, class.output="code-out", warning=FALSE, message=FALSE}
library(sf)
place_sf <- st_as_sf(read.csv("data_cambodia/adress.csv"), coords = c("long", "lat"), crs = 4326)
place_sf
```
```{r echo=FALSE, eval=TRUE}
sf_use_s2(FALSE)
```
To create a `sf` POINT type object with only one pair of coordinate (WGS84, longitude=0.5, latitude = 45.5) :
```{r build_sf2, eval = TRUE, echo = TRUE, nm = TRUE, fig.width=8, class.output="code-out", warning=FALSE, message=FALSE}
library(sf)
test_point <- st_as_sf(data.frame(x = 0.5, y = 45.5), coords = c("x", "y"), crs = 4326)
test_point
```
We can display this object `sf` on an [OpenStreetMap](https://www.openstreetmap.org/) basesmap with the package maptiles `maptiles` [@maptiles].
```{r display_sf, eval = TRUE, echo = TRUE, nm = TRUE, out.width="788px", warning=FALSE, message=FALSE}
library(maptiles)
osm <- get_tiles(x = place_sf, zoom = 12)
plot_tiles(osm)
plot(st_geometry(place_sf), pch = 2, cex = 2, col = "red", add = TRUE)
```
## Geocoding
Serveral pakages alow you to geocode addresses. <img src="img/logo_tidygeocoder.png" align="right" width="120"/> The package `tidygeocoder` [@tidygeocoder] allow the use of a [large number of online geocoding sevices](https://jessecambon.github.io/tidygeocoder/articles/geocoder_services.html). The package `banR` [@banR], which is based on the [National Address Base](https://adresse.data.gouv.fr/), is the particularly suitable for geocoding addresses in France.
......
# Vector Data
# Using vector data
## Importing and exporting data
......@@ -360,4 +360,4 @@ cal_mat$durations[1:2, 1:5]
boxplot(t(cal_mat$durations[,]), cex.axis = 0.7)
```
\ No newline at end of file
```
# Work with Raster Data
# Using raster data
This chapter is largely inspired by two presentation; @MmadelinSIGR and @JNowosadSIGR; carried out as part of the [SIGR2021](https://sigr2021.github.io/site/index.html) thematic school.
......
......@@ -12,7 +12,7 @@ The fonction `mf_map()` is the central function of the package `mapsf` [@mapsf].
- `var`, the name of variable to present ;
- `type`, the type of presentation.
### Example data
### Create a simple map
The following lines import the spatial information layers located in the [geopackage](https://www.geopackage.org/) **cambodia.gpkg** file.
......@@ -32,10 +32,6 @@ hospital = st_read("data_cambodia/cambodia.gpkg", layer = "hospital", quiet = TR
```
### Displaying a background map
Without using types specification, the function `mf_map()` simply display the background map.
```{r mf_base, class.output="code-out", warning=FALSE, message=FALSE}
library(mapsf)
......@@ -368,7 +364,7 @@ To be finalized, a thematic map must contain certain additional elements such as
### Example data
The following lines import the spatial information layers located in the [geopackage](https://www.geopackage.org/) **lot46.gpkg** file.
The following lines import the spatial information layers located in the [geopackage](https://www.geopackage.org/) **cambodia.gpkg** file.
```{r, class.output="code-out", warning=FALSE, message=FALSE}
library(sf)
......@@ -583,7 +579,7 @@ mf_map(district, add = TRUE)
mf_map(dist_selected, col = NA, border = "#29a3a3", lwd = 2, add = TRUE)
```
### Displaying several maps on the sam figure
### Displaying several maps on the same figure
Here you have to use `mfrow` of the function `par()`. The first digit represents the number of of rows and second the number of columns.
......
05-mapping_with_r_files/figure-html/choro-1.png

44.7 KiB

05-mapping_with_r_files/figure-html/choro-incidence-1.png

43.6 KiB

05-mapping_with_r_files/figure-html/choroprop-1.png

50 KiB

05-mapping_with_r_files/figure-html/choropt-1.png

52.2 KiB

05-mapping_with_r_files/figure-html/credit-1.png

35.2 KiB

05-mapping_with_r_files/figure-html/discr3-1.png

29 KiB

05-mapping_with_r_files/figure-html/inset-1.png

41.1 KiB

05-mapping_with_r_files/figure-html/labs-1.png

29.8 KiB

05-mapping_with_r_files/figure-html/layout1-1.png

36.3 KiB

05-mapping_with_r_files/figure-html/linemap-1.png

12.7 KiB

05-mapping_with_r_files/figure-html/logo-1.png

55.1 KiB

05-mapping_with_r_files/figure-html/mf_base-1.png

70.8 KiB

05-mapping_with_r_files/figure-html/mfrow0-1.png

37.2 KiB

05-mapping_with_r_files/figure-html/north-1.png

33.6 KiB

05-mapping_with_r_files/figure-html/pal1-1.png

27 KiB

05-mapping_with_r_files/figure-html/pal2-1.png

3.09 KiB

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