diff --git a/03-vector_data.qmd b/03-vector_data.qmd new file mode 100644 index 0000000000000000000000000000000000000000..1f5cb0b6195784c507065d94e898d69542494f0a --- /dev/null +++ b/03-vector_data.qmd @@ -0,0 +1,364 @@ + +# Vector Data + +## Importing and exporting data + +The `st_read()` and `st_write()` function are used to import and export many types of files. The following lines import the administrative data in district level layer located in the **cambodia.gpkg** [geopackage](https://www.geopackage.org/) file. + +```{r import, class.output="code-out", warning=FALSE, message=FALSE} +library(sf) + +district = st_read("data_cambodia/cambodia.gpkg", layer = "district") #import district data +``` + +The following lines export the **district object** to a **data** folder in geopackage and shapefile format. + +```{r export, class.output="code-out", warning=FALSE, message=FALSE} + +st_write(obj = district, dsn = "data_cambodia/district.gpkg", delete_layer = TRUE) +st_write(obj = district, "data_cambodia/district.shp", layer_options = "ENCODING=UTF-8", delete_layer = TRUE) + +``` + +## Display + +**Preview of the variables** via the function `head()` and `plot()`. + +```{r aff1, nm = TRUE, class.output="code-out", warning=FALSE, message=FALSE} +head(district) +plot(district) +``` + +**for Geometry display** only. + +```{r aff2, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +plot(st_geometry(district)) +``` + +## Coordinate systems + +### Look up the coordinate system of an object + +The function `st_crs()` makes it possible to consult the system of coordinates used and object sf. + +```{r proj1, proj1, class.output="code-out", warning=FALSE, message=FALSE} +st_crs(district) +``` + +### Changing the coordinate system of an object + +The function `st_transform()` allows to change the coordinate system of an sf object, to re-project it. + +```{r, proj2, sm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +plot(st_geometry(district)) +title("WGS 84 / UTM zone 48N") +dist_reproj <- st_transform(district, "epsg:4326") +plot(st_geometry(dist_reproj)) +title("WGS84") +``` + +The [Spatial Reference](http://spatialreference.org/){target="_blank"} site provides reference for a large number of coordinate systems. + +## Selection by attributes + +The object `sf` **are** `data.frame`, so you can select their rows and columns in the same way as `data.frame`. + +```{r selectAttr, class.output="code-out", warning=FALSE, message=FALSE} +# row Selection +district[1:2, ] + +district[district$ADM1_EN == "Phnom Penh", ] + +# column selection +district[district$ADM1_EN == "Phnom Penh", 1:4] +``` + +## Spatial selection + +### Intersections + +Selection of roads that are intersecting **dangkao** district + +```{r intersects, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +road <- st_read("data_cambodia/cambodia.gpkg", layer = "road", quiet = TRUE) +dangkao <- district[district$ADM2_EN == "Dangkao", ] +inter <- st_intersects(x = road, y = dangkao, sparse = FALSE) +head(inter) +dim(inter) +``` + +The **inter** object is a matrix which indicates for each of element of the **road** object (6 elements) whether it intersects each elements the **dangkao** object (1 element). The dimension of the matrix is therefore indeed 6 rows \* 1 column. Note the use of the parameter `sparse = FALSE` here. It is then possible to create a column from this object: + +```{r intersects2, nm =TRUE, class.output="code-out", warning=FALSE, message=FALSE} +road$intersect_dangkao <- inter +plot(st_geometry(dangkao), col = "lightblue") +plot(st_geometry(road), add = TRUE) +plot(st_geometry(road[road$intersect_dangkao, ]), + col = "tomato", lwd = 1.5, add = TRUE) +``` + +#### Difference between `sparse = TRUE` and `sparse = FALSE` + +```{r st_intersparse, echo =FALSE, eval = TRUE, class.output="code-out", warning=FALSE, message=FALSE} +library(sf) +set.seed(41) +x <- mapsf::mf_get_mtq() +grid <- st_make_grid(x = x, n = c(2,2)) +grid <- st_sf(id = 1:4, geom = grid) +pt <- st_sample(grid, size = 8) +pt <- st_sf(id = letters[1:length(pt)], geom = pt) + +library(mapsf) +mf_init(grid, expandBB = c(0, 0, 0, .3)) +mf_map(grid, add = T) +mf_label(grid, "id", cex = 2, pos = 3) +mf_map(pt, add = T, pch = 4, cex = 1.2, lwd = 2, col = "red") +mf_label(pt, "id", cex = 1, col = "red", font = 3, pos = 2, overlap = F) +legend(x = "topright", + col = c("black", NA, "red"), + legend = + c(" grid ", NA, " pt "), + pch = c(22,NA,4), + pt.bg = "grey", + pt.cex = c(6,NA, 1.2), + bty = "n") +mf_title("st_intersects()", tab = FALSE, pos = "center") +``` + +- `sparse = TRUE` + +```{r st_intersparse2, class.output="code-out", warning=FALSE, message=FALSE} +inter <- st_intersects(x = grid, y = pt, sparse = TRUE) +inter +``` + +- `sparse = FALSE` + +```{r st_intersparse3, class.output="code-out", warning=FALSE, message=FALSE} +inter <- st_intersects(x = grid, y = pt, sparse = FALSE) +rownames(inter) <- grid$id +colnames(inter) <- pt$id +inter +``` + +### Contains / Within + +Selection of roads contained in the municipality of *Dangkao*. The function `st_within()` works like the function `st_intersects()` + +```{r within, nm = TRUE, class.output="code-out", warning=FALSE, message=FALSE} +road$within_dangkao <- st_within(road, dangkao, sparse = FALSE) +plot(st_geometry(dangkao), col = "lightblue") +plot(st_geometry(road), add = TRUE) +plot(st_geometry(road[road$within_dangkao, ]), col = "tomato", + lwd = 2, add = TRUE) + +``` + +## Operation of geometries + +### Extract centroids + +```{r centroid, nm = TRUE, class.output="code-out", warning=FALSE, message=FALSE} +dist_c <- st_centroid(district) +plot(st_geometry(district)) +plot(st_geometry(dist_c), add = TRUE, cex = 1.2, col = "red", pch = 20) +``` + +### Aggregate polygons + +```{r aggreg, nm = TRUE, class.output="code-out", warning=FALSE, message=FALSE} +cambodia_dist <- st_union(district) +plot(st_geometry(district), col = "lightblue") +plot(st_geometry(cambodia_dist), add = TRUE, lwd = 2, border = "red") +``` + +### Aggregate polygons based on a variable + +```{r aggreg2, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +dist_union <- aggregate(x = district[,c("T_POP")], + by = list(STATUT = district$Status), + FUN = "sum") +plot(dist_union) +``` + +### Create a buffer zone + +```{r buffers, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +dangkao_buffer <- st_buffer(x = dangkao, dist = 1000) +plot(st_geometry(dangkao_buffer), col = "#E8DAEF", lwd=2, border = "#6C3483") +plot(st_geometry(dangkao), add = TRUE, lwd = 2) +``` + +### Making an intersection + +By using the function `st_intersection()` we will cut one layer by another. + +```{r intersect2, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +library(magrittr) +# creation of a buffer zone around the centroid of the municipality of Dangkao district +# using the pipe +zone <- st_geometry(dangkao) %>% + st_centroid() %>% + st_buffer(30000) +plot(st_geometry(district)) +plot(zone, border = "#F06292", lwd = 2, add = TRUE) +dist_z <- st_intersection(x = district, y = zone) +plot(st_geometry(district)) +plot(st_geometry(dist_z), col="#AF7AC5", border="#F9E79F", add=T) +plot(st_geometry(dist_z)) +``` + +### Create regular grid + +The function `st_make_grid()` allows you to create regular grid. The function produce and object `sfc`, you must then use the function `st_sf()` to transform the object `sfc` into and object `sf`. During this transformation we add here a column of unique identifiers. + +```{r grid, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +grid <- st_make_grid(x = district, cellsize = 10000) +grid <- st_sf(ID = 1:length(grid), geom = grid) + +plot(st_geometry(grid), col = "grey", border = "white") +plot(st_geometry(district), border = "grey50", add = TRUE) +``` + +### Counting points in a polygon (in a grid tile) + +```{r intersect3.1, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} + +# selection of grid tiles that intersect the district + +inter <- st_intersects(grid, cambodia_dist, sparse = FALSE) +grid <- grid[inter, ] + +case_cambodia <- st_read("data_cambodia/cambodia.gpkg", layer = "cases" , quiet = TRUE) +plot(st_geometry(grid), col = "grey", border = "white") +plot(st_geometry(case_cambodia), pch = 20, col = "red", add = TRUE, cex = 0.8) + +inter <- st_intersects(grid, case_cambodia, sparse = TRUE) +length(inter) + +``` + +Here we use the argument `sparse = TRUE`. The **inter** object is a list the length of the **grid** and each item in the list contain the index of the object items of **cases** and **grid** intersection. + +For example **grid tile** 35th intersect with four **cases** 97, 138, 189, 522, 624, 696 + +```{r intersect3.3, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +inter[35] +plot(st_geometry(grid[35, ])) +plot(st_geometry(case_cambodia), add = T) +plot(st_geometry(case_cambodia[c(97, 138, 189, 522, 624, 696), ]), + col = "red", pch = 19, add = TRUE) +``` + +To count number of **case**, simply go to the list and report length of the elements. + +```{r intersect3.4, class.output="code-out", warning=FALSE, message=FALSE} +grid$nb_case <- sapply(X = inter, FUN = length) # create 'nb_case' column to store number of health centers in each grid tile +plot(grid["nb_case"]) +``` + +### Aggregate point values into polygons + +In this example we import a csv file that contain data from a population grid. Once import we transform it `data.frame` into an object `sf`. + +The objective is to aggregate the values id these points (the population contained in the "DENs" field) in the municipalities of the district. + +```{r agval, class.output="code-out", warning=FALSE, message=FALSE} + +pp_pop_raw <- read.csv("data_cambodia/pp_pop_dens.csv") # import file +pp_pop_raw$id <- 1:nrow(pp_pop_raw) # adding a unique identifier +pp_pop <- st_as_sf(pp_pop_raw, coords = c("X", "Y"), crs = 32648) # Transform into object sf +pp_pop <- st_transform(pp_pop, st_crs(district)) # Transform projection +inter <- st_intersection(pp_pop, district) # Intersection +inter + +``` + +By using the function `st_intersection()` we add to each point of the grid all the information on the municipality in which it is located. + +We can then use the function `aggregate()` to aggregate the population by municipalities. + +```{r agval2, class.output="code-out", warning=FALSE, message=FALSE} +resultat <- aggregate(x = list(pop_from_grid = inter$DENs), + by = list(ADM2_EN = inter$ADM2_EN), + FUN = "sum") +head(resultat) +``` + +We can then create a new object with this result. + +```{r agval3, class.output="code-out", warning=FALSE, message=FALSE} +dist_result <- merge(district, resultat, by = "ADM2_EN", all.x = TRUE) +dist_result +``` + +## Measurements + +### Create a distance matrix + +If the dataset's projection system is specified, the distance are expressed in the projection measurement unit (most often in meter) + +```{r distance, nm=TRUE, class.output="code-out", warning=FALSE, message=FALSE} +mat <- st_distance(x = dist_c, y = dist_c) +mat[1:5,1:5] +``` + +### Calculate routes + +<img src="img/logo_osrm.svg" align="right" width="120"/> The package `osrm` [@R-osrm] acts as an interface R and the [OSRM](http://project-osrm.org/) [@luxen-vetter-2011]. This package allows to calculate time and distance matrices, road routes, isochrones. The package uses the OSRM demo server by default. In case of intensive use [it is strongly recommended to use your own instance of OSRM (with Docker)](https://github.com/Project-OSRM/osrm-backend#using-docker). + +#### Calculate a route + +The fonction `osrmRoute()` allows you to calculate routes. + +```{r osrmroute, fig.width = 3, fig.height = 5, class.output="code-out", warning=FALSE, message=FALSE} +library(sf) +library(osrm) +library(maptiles) +district <- st_read("data_cambodia/cambodia.gpkg",layer = "district", quiet = TRUE) +district <- st_transform(district, 32648) + +odongk <- district[district$ADM2_PCODE == "KH0505", ] # Itinerary between Odongk district and Toul Kouk +takmau <- district[district$ADM2_PCODE == "KH0811",] +route <- osrmRoute(src = odongk, + dst = takmau, + returnclass = "sf") +osm <- get_tiles(route, crop = TRUE) +plot_tiles(osm) +plot(st_geometry(route), col = "#b23a5f", lwd = 6, add = T) +plot(st_geometry(route), col = "#eee0e5", lwd = 1, add = T) +``` + +#### Calculation of a time matrix + +The function `osrmTable()` makes it possible to calculate matrices of distances or times by road. + +In this example we calculate a time matrix between 2 addresses and health centers in Phnom Penh on foot. + +```{r osrmtable, fig.width = 8, class.output="code-out", warning=FALSE, message=FALSE} +library(sf) +library(tidygeocoder) +hospital <- st_read("data_cambodia/cambodia.gpkg",layer= "hospital", quiet = TRUE) + +hospital_pp <- hospital[hospital$PCODE == "12", ] # Selection of health centers in Phnom Penh + +adresses <- data.frame(adr = c("Royal Palace Park, Phnom Penh Phnom, Cambodia", + "Wat Phnom Daun Penh, Phnom Penh, Cambodia")) # Geocoding of 2 addresses in Phnom Penh + +places <- tidygeocoder::geocode(.tbl = adresses,address = adr) +places + + +# Calculation of the distance matrix between the 2 addresses and the health center in Phnom Penh + +cal_mat <- osrmTable(src = places[,c(1,3,2)], + dst = hospital_pp, + osrm.profile = "foot") + +cal_mat$durations[1:2, 1:5] + +# Which address has better accessibility to health center in Phnom Penh? + +boxplot(t(cal_mat$durations[,]), cex.axis = 0.7) + +``` \ No newline at end of file diff --git a/_quarto.yml b/_quarto.yml index 53346cba9367565f3a08de025c3e5af0e7c7977a..54a76643951d3e71a3c3dad31ea22b51308d4469 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -14,6 +14,7 @@ book: - index.qmd - 01-introduction.qmd - 02-data_acquisition.qmd + - 03-vector_data.qmd - references.qmd bibliography: references.bib diff --git a/data_cambodia/district.gpkg b/data_cambodia/district.gpkg index ff904f517fd2feeadeefb384553361ec20023184..1ad5fa038d31e57a0c363dfb82e2dd0138dcf642 100644 Binary files a/data_cambodia/district.gpkg and b/data_cambodia/district.gpkg differ diff --git a/public/02-data_acquisition.html b/public/02-data_acquisition.html index 6a5b995037238ecc70943f59979d7bc1705afc4f..cba5b588824651c804fe95dac33adf9547cf2c79 100644 --- a/public/02-data_acquisition.html +++ b/public/02-data_acquisition.html @@ -107,7 +107,7 @@ div.csl-indent { <script src="site_libs/quarto-search/fuse.min.js"></script> <script src="site_libs/quarto-search/quarto-search.js"></script> <meta name="quarto:offset" content="./"> -<link href="./references.html" rel="next"> +<link href="./03-vector_data.html" rel="next"> <link href="./01-introduction.html" rel="prev"> <script src="site_libs/quarto-html/quarto.js"></script> <script src="site_libs/quarto-html/popper.min.js"></script> @@ -205,6 +205,11 @@ div.csl-indent { <div class="sidebar-item-container"> <a href="./02-data_acquisition.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">2</span> <span class="chapter-title">Data Acquisition</span></a> </div> +</li> + <li class="sidebar-item"> + <div class="sidebar-item-container"> + <a href="./03-vector_data.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span> <span class="chapter-title">03-vector_data.html</span></a> + </div> </li> <li class="sidebar-item"> <div class="sidebar-item-container"> @@ -751,8 +756,8 @@ window.document.addEventListener("DOMContentLoaded", function (event) { </a> </div> <div class="nav-page nav-page-next"> - <a href="./references.html" class="pagination-link"> - <span class="nav-page-text">References</span> <i class="bi bi-arrow-right-short"></i> + <a href="./03-vector_data.html" class="pagination-link"> + <span class="nav-page-text"><span class="chapter-number">3</span> <span class="chapter-title">03-vector_data.html</span></span> <i class="bi bi-arrow-right-short"></i> </a> </div> </nav> diff --git a/public/03-vector_data.html b/public/03-vector_data.html new file mode 100644 index 0000000000000000000000000000000000000000..7d0efb159055a4e0ced8f3dcab1e745bb7766bbe --- /dev/null +++ b/public/03-vector_data.html @@ -0,0 +1,1011 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head> + +<meta charset="utf-8"> +<meta name="generator" content="quarto-0.9.617"> + +<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> + + +<title>Mapping and spatial analyses in R for One Health studies - 3 Vector Data</title> +<style> +code{white-space: pre-wrap;} +span.smallcaps{font-variant: small-caps;} +span.underline{text-decoration: underline;} +div.column{display: inline-block; vertical-align: top; width: 50%;} +div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} +ul.task-list{list-style: none;} +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 { } /* 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 { } /* 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 */ +</style> + + +<script src="site_libs/quarto-nav/quarto-nav.js"></script> +<script src="site_libs/quarto-nav/headroom.min.js"></script> +<script src="site_libs/clipboard/clipboard.min.js"></script> +<script src="site_libs/quarto-search/autocomplete.umd.js"></script> +<script src="site_libs/quarto-search/fuse.min.js"></script> +<script src="site_libs/quarto-search/quarto-search.js"></script> +<meta name="quarto:offset" content="./"> +<link href="./references.html" rel="next"> +<link href="./02-data_acquisition.html" rel="prev"> +<script src="site_libs/quarto-html/quarto.js"></script> +<script src="site_libs/quarto-html/popper.min.js"></script> +<script src="site_libs/quarto-html/tippy.umd.min.js"></script> +<script src="site_libs/quarto-html/anchor.min.js"></script> +<link href="site_libs/quarto-html/tippy.css" rel="stylesheet"> +<link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles"> +<script src="site_libs/bootstrap/bootstrap.min.js"></script> +<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet"> +<link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet"> +<script id="quarto-search-options" type="application/json">{ + "location": "sidebar", + "copy-button": false, + "collapse-after": 3, + "panel-placement": "start", + "type": "textbox", + "limit": 20, + "language": { + "search-no-results-text": "No results", + "search-matching-documents-text": "matching documents", + "search-copy-link-title": "Copy link to search", + "search-hide-matches-text": "Hide additional matches", + "search-more-match-text": "more match in this document", + "search-more-matches-text": "more matches in this document", + "search-clear-button-title": "Clear", + "search-detached-cancel-button-title": "Cancel", + "search-submit-button-title": "Submit" + } +}</script> + + +<link rel="stylesheet" href="styles.css"> +</head> + +<body class="nav-sidebar floating"> + +<div id="quarto-search-results"></div> + <header id="quarto-header" class="headroom fixed-top"> + <nav class="quarto-secondary-nav" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }"> + <div class="container-fluid d-flex justify-content-between"> + <h1 class="quarto-secondary-nav-title"><span class="chapter-number">3</span> <span class="chapter-title">Vector Data</span></h1> + <button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation"> + <i class="bi bi-chevron-right"></i> + </button> + </div> + </nav> +</header> +<!-- content --> +<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article"> +<!-- sidebar --> + <nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto"> + <div class="pt-lg-2 mt-2 text-left sidebar-header"> + <div class="sidebar-title mb-0 py-0"> + <a href="./">Mapping and spatial analyses in R for One Health studies</a> + <div class="sidebar-tools-main"> + <a href="https://forge.ird.fr/espace-dev/personnels/longour/rspatial-for-onehealth" title="Source Code" class="sidebar-tool px-1"><i class="bi bi-git"></i></a> +</div> + </div> + </div> + <div class="mt-2 flex-shrink-0 align-items-center"> + <div class="sidebar-search"> + <div id="quarto-search" class="" title="Search"></div> + </div> + </div> + <div class="sidebar-menu-container"> + <ul class="list-unstyled mt-1"> + <li class="sidebar-item"> + <div class="sidebar-item-container"> + <a href="./index.html" class="sidebar-item-text sidebar-link">Preface</a> + </div> +</li> + <li class="sidebar-item"> + <div class="sidebar-item-container"> + <a href="./01-introduction.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span> <span class="chapter-title">Introduction</span></a> + </div> +</li> + <li class="sidebar-item"> + <div class="sidebar-item-container"> + <a href="./02-data_acquisition.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span> <span class="chapter-title">Data Acquisition</span></a> + </div> +</li> + <li class="sidebar-item"> + <div class="sidebar-item-container"> + <a href="./03-vector_data.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">3</span> <span class="chapter-title">Vector Data</span></a> + </div> +</li> + <li class="sidebar-item"> + <div class="sidebar-item-container"> + <a href="./references.html" class="sidebar-item-text sidebar-link">References</a> + </div> +</li> + </ul> + </div> +</nav> +<!-- margin-sidebar --> + <div id="quarto-margin-sidebar" class="sidebar margin-sidebar"> + <nav id="TOC" role="doc-toc"> + <h2 id="toc-title">Table of contents</h2> + + <ul> + <li><a href="#importing-and-exporting-data" id="toc-importing-and-exporting-data" class="nav-link active" data-scroll-target="#importing-and-exporting-data"> <span class="header-section-number">3.1</span> Importing and exporting data</a></li> + <li><a href="#display" id="toc-display" class="nav-link" data-scroll-target="#display"> <span class="header-section-number">3.2</span> Display</a></li> + <li><a href="#coordinate-systems" id="toc-coordinate-systems" class="nav-link" data-scroll-target="#coordinate-systems"> <span class="header-section-number">3.3</span> Coordinate systems</a> + <ul class="collapse"> + <li><a href="#look-up-the-coordinate-system-of-an-object" id="toc-look-up-the-coordinate-system-of-an-object" class="nav-link" data-scroll-target="#look-up-the-coordinate-system-of-an-object"> <span class="header-section-number">3.3.1</span> Look up the coordinate system of an object</a></li> + <li><a href="#changing-the-coordinate-system-of-an-object" id="toc-changing-the-coordinate-system-of-an-object" class="nav-link" data-scroll-target="#changing-the-coordinate-system-of-an-object"> <span class="header-section-number">3.3.2</span> Changing the coordinate system of an object</a></li> + </ul></li> + <li><a href="#selection-by-attributes" id="toc-selection-by-attributes" class="nav-link" data-scroll-target="#selection-by-attributes"> <span class="header-section-number">3.4</span> Selection by attributes</a></li> + <li><a href="#spatial-selection" id="toc-spatial-selection" class="nav-link" data-scroll-target="#spatial-selection"> <span class="header-section-number">3.5</span> Spatial selection</a> + <ul class="collapse"> + <li><a href="#intersections" id="toc-intersections" class="nav-link" data-scroll-target="#intersections"> <span class="header-section-number">3.5.1</span> Intersections</a></li> + <li><a href="#contains-within" id="toc-contains-within" class="nav-link" data-scroll-target="#contains-within"> <span class="header-section-number">3.5.2</span> Contains / Within</a></li> + </ul></li> + <li><a href="#operation-of-geometries" id="toc-operation-of-geometries" class="nav-link" data-scroll-target="#operation-of-geometries"> <span class="header-section-number">3.6</span> Operation of geometries</a> + <ul class="collapse"> + <li><a href="#extract-centroids" id="toc-extract-centroids" class="nav-link" data-scroll-target="#extract-centroids"> <span class="header-section-number">3.6.1</span> Extract centroids</a></li> + <li><a href="#aggregate-polygons" id="toc-aggregate-polygons" class="nav-link" data-scroll-target="#aggregate-polygons"> <span class="header-section-number">3.6.2</span> Aggregate polygons</a></li> + <li><a href="#aggregate-polygons-based-on-a-variable" id="toc-aggregate-polygons-based-on-a-variable" class="nav-link" data-scroll-target="#aggregate-polygons-based-on-a-variable"> <span class="header-section-number">3.6.3</span> Aggregate polygons based on a variable</a></li> + <li><a href="#create-a-buffer-zone" id="toc-create-a-buffer-zone" class="nav-link" data-scroll-target="#create-a-buffer-zone"> <span class="header-section-number">3.6.4</span> Create a buffer zone</a></li> + <li><a href="#making-an-intersection" id="toc-making-an-intersection" class="nav-link" data-scroll-target="#making-an-intersection"> <span class="header-section-number">3.6.5</span> Making an intersection</a></li> + <li><a href="#create-regular-grid" id="toc-create-regular-grid" class="nav-link" data-scroll-target="#create-regular-grid"> <span class="header-section-number">3.6.6</span> Create regular grid</a></li> + <li><a href="#counting-points-in-a-polygon-in-a-grid-tile" id="toc-counting-points-in-a-polygon-in-a-grid-tile" class="nav-link" data-scroll-target="#counting-points-in-a-polygon-in-a-grid-tile"> <span class="header-section-number">3.6.7</span> Counting points in a polygon (in a grid tile)</a></li> + <li><a href="#aggregate-point-values-into-polygons" id="toc-aggregate-point-values-into-polygons" class="nav-link" data-scroll-target="#aggregate-point-values-into-polygons"> <span class="header-section-number">3.6.8</span> Aggregate point values into polygons</a></li> + </ul></li> + <li><a href="#measurements" id="toc-measurements" class="nav-link" data-scroll-target="#measurements"> <span class="header-section-number">3.7</span> Measurements</a> + <ul class="collapse"> + <li><a href="#create-a-distance-matrix" id="toc-create-a-distance-matrix" class="nav-link" data-scroll-target="#create-a-distance-matrix"> <span class="header-section-number">3.7.1</span> Create a distance matrix</a></li> + <li><a href="#calculate-routes" id="toc-calculate-routes" class="nav-link" data-scroll-target="#calculate-routes"> <span class="header-section-number">3.7.2</span> Calculate routes</a></li> + </ul></li> + </ul> +</nav> + </div> +<!-- main --> +<main class="content" id="quarto-document-content"> + +<header id="title-block-header" class="quarto-title-block default"> +<div class="quarto-title"> +<h1 class="title d-none d-lg-block"><span class="chapter-number">3</span> <span class="chapter-title">Vector Data</span></h1> +</div> + + + +<div class="quarto-title-meta"> + + + + </div> + + +</header> + +<section id="importing-and-exporting-data" class="level2" data-number="3.1"> +<h2 data-number="3.1" class="anchored" data-anchor-id="importing-and-exporting-data"><span class="header-section-number">3.1</span> Importing and exporting data</h2> +<p>The <code>st_read()</code> and <code>st_write()</code> function are used to import and export many types of files. The following lines import the administrative data in district level layer located in the <strong>cambodia.gpkg</strong> <a href="https://www.geopackage.org/">geopackage</a> file.</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> +<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>district <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"district"</span>) <span class="co">#import district data</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/GitHub/rspatial-for-onehealth/data_cambodia/cambodia.gpkg' + using driver `GPKG' +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> +<p>The following lines export the <strong>district object</strong> to a <strong>data</strong> folder in geopackage and shapefile format.</p> +<div class="cell"> +<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><span class="fu">st_write</span>(<span class="at">obj =</span> district, <span class="at">dsn =</span> <span class="st">"data_cambodia/district.gpkg"</span>, <span class="at">delete_layer =</span> <span class="cn">TRUE</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>Deleting layer `district' using driver `GPKG' +Writing layer `district' to data source + `data_cambodia/district.gpkg' using driver `GPKG' +Writing 197 features with 10 fields and geometry type Multi Polygon.</code></pre> +</div> +<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_write</span>(<span class="at">obj =</span> district, <span class="st">"data_cambodia/district.shp"</span>, <span class="at">layer_options =</span> <span class="st">"ENCODING=UTF-8"</span>, <span class="at">delete_layer =</span> <span class="cn">TRUE</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>Deleting layer `district' using driver `ESRI Shapefile' +Writing layer `district' to data source + `data_cambodia/district.shp' using driver `ESRI Shapefile' +options: ENCODING=UTF-8 +Writing 197 features with 10 fields and geometry type Multi Polygon.</code></pre> +</div> +</div> +</section> +<section id="display" class="level2" data-number="3.2"> +<h2 data-number="3.2" class="anchored" data-anchor-id="display"><span class="header-section-number">3.2</span> Display</h2> +<p><strong>Preview of the variables</strong> via the function <code>head()</code> and <code>plot()</code>.</p> +<div class="cell" data-nm="true"> +<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><span class="fu">head</span>(district)</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>Simple feature collection with 6 features and 10 fields +Geometry type: MULTIPOLYGON +Dimension: XY +Bounding box: xmin: 300266.9 ymin: 1180566 xmax: 767313.9 ymax: 1563861 +Projected CRS: WGS 84 / UTM zone 48N + ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP Area.Km2. +1 Aek Phnum KH0205 Battambang KH02 41500 43916 85416 1067.8638 +2 Andoung Meas KH1601 Ratanak Kiri KH16 7336 7372 14708 837.7064 +3 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 183.9050 +4 Angkor Borei KH2101 Takeo KH21 26306 27168 53474 301.0502 +5 Angkor Chey KH0701 Kampot KH07 42448 44865 87313 316.7576 +6 Angkor Chum KH1701 Siemreap KH17 34269 34576 68845 478.6988 + Status DENs geom +1 <4500km2 79.98773 MULTIPOLYGON (((306568.1 14... +2 <4500km2 17.55747 MULTIPOLYGON (((751459.2 15... +3 <4500km2 503.39580 MULTIPOLYGON (((471954.3 12... +4 <4500km2 177.62485 MULTIPOLYGON (((490048.2 12... +5 <4500km2 275.64610 MULTIPOLYGON (((462702.2 12... +6 <4500km2 143.81696 MULTIPOLYGON (((363642.5 15...</code></pre> +</div> +<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(district)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/aff1-1.png" class="img-fluid" width="672"></p> +</div> +</div> +<p><strong>for Geometry display</strong> only.</p> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(district))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/aff2-1.png" class="img-fluid" width="672"></p> +</div> +</div> +</section> +<section id="coordinate-systems" class="level2" data-number="3.3"> +<h2 data-number="3.3" class="anchored" data-anchor-id="coordinate-systems"><span class="header-section-number">3.3</span> Coordinate systems</h2> +<section id="look-up-the-coordinate-system-of-an-object" class="level3" data-number="3.3.1"> +<h3 data-number="3.3.1" class="anchored" data-anchor-id="look-up-the-coordinate-system-of-an-object"><span class="header-section-number">3.3.1</span> Look up the coordinate system of an object</h3> +<p>The function <code>st_crs()</code> makes it possible to consult the system of coordinates used and object sf.</p> +<div class="cell"> +<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">st_crs</span>(district)</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>Coordinate Reference System: + User input: WGS 84 / UTM zone 48N + wkt: +PROJCRS["WGS 84 / UTM zone 48N", + BASEGEOGCRS["WGS 84", + ENSEMBLE["World Geodetic System 1984 ensemble", + MEMBER["World Geodetic System 1984 (Transit)"], + MEMBER["World Geodetic System 1984 (G730)"], + MEMBER["World Geodetic System 1984 (G873)"], + MEMBER["World Geodetic System 1984 (G1150)"], + MEMBER["World Geodetic System 1984 (G1674)"], + MEMBER["World Geodetic System 1984 (G1762)"], + MEMBER["World Geodetic System 1984 (G2139)"], + ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1]], + ENSEMBLEACCURACY[2.0]], + PRIMEM["Greenwich",0, + ANGLEUNIT["degree",0.0174532925199433]], + ID["EPSG",4326]], + CONVERSION["UTM zone 48N", + METHOD["Transverse Mercator", + ID["EPSG",9807]], + PARAMETER["Latitude of natural origin",0, + ANGLEUNIT["degree",0.0174532925199433], + ID["EPSG",8801]], + PARAMETER["Longitude of natural origin",105, + ANGLEUNIT["degree",0.0174532925199433], + ID["EPSG",8802]], + PARAMETER["Scale factor at natural origin",0.9996, + SCALEUNIT["unity",1], + ID["EPSG",8805]], + PARAMETER["False easting",500000, + LENGTHUNIT["metre",1], + ID["EPSG",8806]], + PARAMETER["False northing",0, + LENGTHUNIT["metre",1], + ID["EPSG",8807]]], + CS[Cartesian,2], + AXIS["(E)",east, + ORDER[1], + LENGTHUNIT["metre",1]], + AXIS["(N)",north, + ORDER[2], + LENGTHUNIT["metre",1]], + USAGE[ + SCOPE["Engineering survey, topographic mapping."], + AREA["Between 102°E and 108°E, northern hemisphere between equator and 84°N, onshore and offshore. Cambodia. China. Indonesia. Laos. Malaysia - West Malaysia. Mongolia. Russian Federation. Singapore. Thailand. Vietnam."], + BBOX[0,102,84,108]], + ID["EPSG",32648]]</code></pre> +</div> +</div> +</section> +<section id="changing-the-coordinate-system-of-an-object" class="level3" data-number="3.3.2"> +<h3 data-number="3.3.2" class="anchored" data-anchor-id="changing-the-coordinate-system-of-an-object"><span class="header-section-number">3.3.2</span> Changing the coordinate system of an object</h3> +<p>The function <code>st_transform()</code> allows to change the coordinate system of an sf object, to re-project it.</p> +<div class="cell" data-sm="true"> +<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(district))</span> +<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="fu">title</span>(<span class="st">"WGS 84 / UTM zone 48N"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/proj2-1.png" class="img-fluid" width="672"></p> +</div> +<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>dist_reproj <span class="ot"><-</span> <span class="fu">st_transform</span>(district, <span class="st">"epsg:4326"</span>)</span> +<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(dist_reproj))</span> +<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="fu">title</span>(<span class="st">"WGS84"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/proj2-2.png" class="img-fluid" width="672"></p> +</div> +</div> +<p>The <a href="http://spatialreference.org/" target="_blank">Spatial Reference</a> site provides reference for a large number of coordinate systems.</p> +</section> +</section> +<section id="selection-by-attributes" class="level2" data-number="3.4"> +<h2 data-number="3.4" class="anchored" data-anchor-id="selection-by-attributes"><span class="header-section-number">3.4</span> Selection by attributes</h2> +<p>The object <code>sf</code> <strong>are</strong> <code>data.frame</code>, so you can select their rows and columns in the same way as <code>data.frame</code>.</p> +<div class="cell"> +<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="co"># row Selection</span></span> +<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>district[<span class="dv">1</span><span class="sc">:</span><span class="dv">2</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>Simple feature collection with 2 features and 10 fields +Geometry type: MULTIPOLYGON +Dimension: XY +Bounding box: xmin: 300266.9 ymin: 1449408 xmax: 767313.9 ymax: 1563861 +Projected CRS: WGS 84 / UTM zone 48N + ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP Area.Km2. +1 Aek Phnum KH0205 Battambang KH02 41500 43916 85416 1067.8638 +2 Andoung Meas KH1601 Ratanak Kiri KH16 7336 7372 14708 837.7064 + Status DENs geom +1 <4500km2 79.98773 MULTIPOLYGON (((306568.1 14... +2 <4500km2 17.55747 MULTIPOLYGON (((751459.2 15...</code></pre> +</div> +<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>district[district<span class="sc">$</span>ADM1_EN <span class="sc">==</span> <span class="st">"Phnom Penh"</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>Simple feature collection with 12 features and 10 fields +Geometry type: MULTIPOLYGON +Dimension: XY +Bounding box: xmin: 468677.5 ymin: 1262590 xmax: 505351.9 ymax: 1297419 +Projected CRS: WGS 84 / UTM zone 48N +First 10 features: + ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP +29 Chamkar Mon KH1201 Phnom Penh KH12 52278 54478 106756 +31 Chbar Ampov KH1212 Phnom Penh KH12 64816 68243 133059 +43 Chraoy Chongvar KH1210 Phnom Penh KH12 30920 31087 62007 +48 Dangkao KH1205 Phnom Penh KH12 46999 48525 95524 +50 Doun Penh KH1202 Phnom Penh KH12 33844 36471 70315 +93 Mean Chey KH1206 Phnom Penh KH12 68381 70366 138747 +117 Praek Pnov KH1211 Phnom Penh KH12 27566 27698 55264 +118 Prampir Meakkakra KH1203 Phnom Penh KH12 31091 33687 64778 +133 Pur SenChey KH1209 Phnom Penh KH12 95050 109297 204347 +141 Russey Keo KH1207 Phnom Penh KH12 67357 68419 135776 + Area.Km2. Status DENs geom +29 11.049600 <4500km2 9661.5265 MULTIPOLYGON (((494709.4 12... +31 86.780498 <4500km2 1533.2823 MULTIPOLYGON (((498855.3 12... +43 85.609156 <4500km2 724.3034 MULTIPOLYGON (((491161.3 12... +48 113.774833 <4500km2 839.5881 MULTIPOLYGON (((489191.1 12... +50 7.734808 <4500km2 9090.7234 MULTIPOLYGON (((492447.1 12... +93 28.998026 <4500km2 4784.7051 MULTIPOLYGON (((491068.2 12... +117 115.384300 <4500km2 478.9560 MULTIPOLYGON (((481483.3 12... +118 2.224892 <4500km2 29115.1253 MULTIPOLYGON (((491067.6 12... +133 148.357984 <4500km2 1377.3913 MULTIPOLYGON (((479078.8 12... +141 23.381517 <4500km2 5806.9800 MULTIPOLYGON (((490264.8 12...</code></pre> +</div> +<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="co"># column selection</span></span> +<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>district[district<span class="sc">$</span>ADM1_EN <span class="sc">==</span> <span class="st">"Phnom Penh"</span>, <span class="dv">1</span><span class="sc">:</span><span class="dv">4</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>Simple feature collection with 12 features and 4 fields +Geometry type: MULTIPOLYGON +Dimension: XY +Bounding box: xmin: 468677.5 ymin: 1262590 xmax: 505351.9 ymax: 1297419 +Projected CRS: WGS 84 / UTM zone 48N +First 10 features: + ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE +29 Chamkar Mon KH1201 Phnom Penh KH12 +31 Chbar Ampov KH1212 Phnom Penh KH12 +43 Chraoy Chongvar KH1210 Phnom Penh KH12 +48 Dangkao KH1205 Phnom Penh KH12 +50 Doun Penh KH1202 Phnom Penh KH12 +93 Mean Chey KH1206 Phnom Penh KH12 +117 Praek Pnov KH1211 Phnom Penh KH12 +118 Prampir Meakkakra KH1203 Phnom Penh KH12 +133 Pur SenChey KH1209 Phnom Penh KH12 +141 Russey Keo KH1207 Phnom Penh KH12 + geom +29 MULTIPOLYGON (((494709.4 12... +31 MULTIPOLYGON (((498855.3 12... +43 MULTIPOLYGON (((491161.3 12... +48 MULTIPOLYGON (((489191.1 12... +50 MULTIPOLYGON (((492447.1 12... +93 MULTIPOLYGON (((491068.2 12... +117 MULTIPOLYGON (((481483.3 12... +118 MULTIPOLYGON (((491067.6 12... +133 MULTIPOLYGON (((479078.8 12... +141 MULTIPOLYGON (((490264.8 12...</code></pre> +</div> +</div> +</section> +<section id="spatial-selection" class="level2" data-number="3.5"> +<h2 data-number="3.5" class="anchored" data-anchor-id="spatial-selection"><span class="header-section-number">3.5</span> Spatial selection</h2> +<section id="intersections" class="level3" data-number="3.5.1"> +<h3 data-number="3.5.1" class="anchored" data-anchor-id="intersections"><span class="header-section-number">3.5.1</span> Intersections</h3> +<p>Selection of roads that are intersecting <strong>dangkao</strong> district</p> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>road <span class="ot"><-</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 class="at">quiet =</span> <span class="cn">TRUE</span>)</span> +<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>dangkao <span class="ot"><-</span> district[district<span class="sc">$</span>ADM2_EN <span class="sc">==</span> <span class="st">"Dangkao"</span>, ]</span> +<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>inter <span class="ot"><-</span> <span class="fu">st_intersects</span>(<span class="at">x =</span> road, <span class="at">y =</span> dangkao, <span class="at">sparse =</span> <span class="cn">FALSE</span>)</span> +<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(inter)</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> [,1] +[1,] TRUE +[2,] TRUE +[3,] TRUE +[4,] TRUE +[5,] TRUE +[6,] TRUE</code></pre> +</div> +<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="fu">dim</span>(inter)</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>[1] 6 1</code></pre> +</div> +</div> +<p>The <strong>inter</strong> object is a matrix which indicates for each of element of the <strong>road</strong> object (6 elements) whether it intersects each elements the <strong>dangkao</strong> object (1 element). The dimension of the matrix is therefore indeed 6 rows * 1 column. Note the use of the parameter <code>sparse = FALSE</code> here. It is then possible to create a column from this object:</p> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a>road<span class="sc">$</span>intersect_dangkao <span class="ot"><-</span> inter</span> +<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(dangkao), <span class="at">col =</span> <span class="st">"lightblue"</span>)</span> +<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(road), <span class="at">add =</span> <span class="cn">TRUE</span>)</span> +<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(road[road<span class="sc">$</span>intersect_dangkao, ]),</span> +<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a> <span class="at">col =</span> <span class="st">"tomato"</span>, <span class="at">lwd =</span> <span class="fl">1.5</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/intersects2-1.png" class="img-fluid" width="672"></p> +</div> +</div> +<section id="difference-between-sparse-true-and-sparse-false" class="level4" data-number="3.5.1.1"> +<h4 data-number="3.5.1.1" class="anchored" data-anchor-id="difference-between-sparse-true-and-sparse-false"><span class="header-section-number">3.5.1.1</span> Difference between <code>sparse = TRUE</code> and <code>sparse = FALSE</code></h4> +<div class="cell"> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/st_intersparse-1.png" class="img-fluid" width="672"></p> +</div> +</div> +<ul> +<li><code>sparse = TRUE</code></li> +</ul> +<div class="cell"> +<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>inter <span class="ot"><-</span> <span class="fu">st_intersects</span>(<span class="at">x =</span> grid, <span class="at">y =</span> pt, <span class="at">sparse =</span> <span class="cn">TRUE</span>)</span> +<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a>inter</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>Sparse geometry binary predicate list of length 4, where the predicate +was `intersects' + 1: (empty) + 2: 6, 7 + 3: 1, 4 + 4: 2, 3, 5, 8</code></pre> +</div> +</div> +<ul> +<li><code>sparse = FALSE</code></li> +</ul> +<div class="cell"> +<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>inter <span class="ot"><-</span> <span class="fu">st_intersects</span>(<span class="at">x =</span> grid, <span class="at">y =</span> pt, <span class="at">sparse =</span> <span class="cn">FALSE</span>)</span> +<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="fu">rownames</span>(inter) <span class="ot"><-</span> grid<span class="sc">$</span>id</span> +<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(inter) <span class="ot"><-</span> pt<span class="sc">$</span>id</span> +<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a>inter</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> a b c d e f g h +1 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE +2 FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE +3 TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE +4 FALSE TRUE TRUE FALSE TRUE FALSE FALSE TRUE</code></pre> +</div> +</div> +</section> +</section> +<section id="contains-within" class="level3" data-number="3.5.2"> +<h3 data-number="3.5.2" class="anchored" data-anchor-id="contains-within"><span class="header-section-number">3.5.2</span> Contains / Within</h3> +<p>Selection of roads contained in the municipality of <em>Dangkao</em>. The function <code>st_within()</code> works like the function <code>st_intersects()</code></p> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a>road<span class="sc">$</span>within_dangkao <span class="ot"><-</span> <span class="fu">st_within</span>(road, dangkao, <span class="at">sparse =</span> <span class="cn">FALSE</span>)</span> +<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(dangkao), <span class="at">col =</span> <span class="st">"lightblue"</span>)</span> +<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(road), <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/within-1.png" class="img-fluid" width="672"></p> +</div> +<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(road[road<span class="sc">$</span>within_dangkao, ]), <span class="at">col =</span> <span class="st">"tomato"</span>,</span> +<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a> <span class="at">lwd =</span> <span class="dv">2</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +</div> +</section> +</section> +<section id="operation-of-geometries" class="level2" data-number="3.6"> +<h2 data-number="3.6" class="anchored" data-anchor-id="operation-of-geometries"><span class="header-section-number">3.6</span> Operation of geometries</h2> +<section id="extract-centroids" class="level3" data-number="3.6.1"> +<h3 data-number="3.6.1" class="anchored" data-anchor-id="extract-centroids"><span class="header-section-number">3.6.1</span> Extract centroids</h3> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a>dist_c <span class="ot"><-</span> <span class="fu">st_centroid</span>(district)</span> +<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(district))</span> +<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(dist_c), <span class="at">add =</span> <span class="cn">TRUE</span>, <span class="at">cex =</span> <span class="fl">1.2</span>, <span class="at">col =</span> <span class="st">"red"</span>, <span class="at">pch =</span> <span class="dv">20</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/centroid-1.png" class="img-fluid" width="672"></p> +</div> +</div> +</section> +<section id="aggregate-polygons" class="level3" data-number="3.6.2"> +<h3 data-number="3.6.2" class="anchored" data-anchor-id="aggregate-polygons"><span class="header-section-number">3.6.2</span> Aggregate polygons</h3> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>cambodia_dist <span class="ot"><-</span> <span class="fu">st_union</span>(district) </span> +<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(district), <span class="at">col =</span> <span class="st">"lightblue"</span>)</span> +<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(cambodia_dist), <span class="at">add =</span> <span class="cn">TRUE</span>, <span class="at">lwd =</span> <span class="dv">2</span>, <span class="at">border =</span> <span class="st">"red"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/aggreg-1.png" class="img-fluid" width="672"></p> +</div> +</div> +</section> +<section id="aggregate-polygons-based-on-a-variable" class="level3" data-number="3.6.3"> +<h3 data-number="3.6.3" class="anchored" data-anchor-id="aggregate-polygons-based-on-a-variable"><span class="header-section-number">3.6.3</span> Aggregate polygons based on a variable</h3> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a>dist_union <span class="ot"><-</span> <span class="fu">aggregate</span>(<span class="at">x =</span> district[,<span class="fu">c</span>(<span class="st">"T_POP"</span>)],</span> +<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a> <span class="at">by =</span> <span class="fu">list</span>(<span class="at">STATUT =</span> district<span class="sc">$</span>Status),</span> +<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a> <span class="at">FUN =</span> <span class="st">"sum"</span>)</span> +<span id="cb34-4"><a href="#cb34-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(dist_union)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/aggreg2-1.png" class="img-fluid" width="672"></p> +</div> +</div> +</section> +<section id="create-a-buffer-zone" class="level3" data-number="3.6.4"> +<h3 data-number="3.6.4" class="anchored" data-anchor-id="create-a-buffer-zone"><span class="header-section-number">3.6.4</span> Create a buffer zone</h3> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a>dangkao_buffer <span class="ot"><-</span> <span class="fu">st_buffer</span>(<span class="at">x =</span> dangkao, <span class="at">dist =</span> <span class="dv">1000</span>)</span> +<span id="cb35-2"><a href="#cb35-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(dangkao_buffer), <span class="at">col =</span> <span class="st">"#E8DAEF"</span>, <span class="at">lwd=</span><span class="dv">2</span>, <span class="at">border =</span> <span class="st">"#6C3483"</span>)</span> +<span id="cb35-3"><a href="#cb35-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(dangkao), <span class="at">add =</span> <span class="cn">TRUE</span>, <span class="at">lwd =</span> <span class="dv">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/buffers-1.png" class="img-fluid" width="672"></p> +</div> +</div> +</section> +<section id="making-an-intersection" class="level3" data-number="3.6.5"> +<h3 data-number="3.6.5" class="anchored" data-anchor-id="making-an-intersection"><span class="header-section-number">3.6.5</span> Making an intersection</h3> +<p>By using the function <code>st_intersection()</code> we will cut one layer by another.</p> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(magrittr)</span> +<span id="cb36-2"><a href="#cb36-2" aria-hidden="true" tabindex="-1"></a><span class="co"># creation of a buffer zone around the centroid of the municipality of Dangkao district</span></span> +<span id="cb36-3"><a href="#cb36-3" aria-hidden="true" tabindex="-1"></a><span class="co"># using the pipe</span></span> +<span id="cb36-4"><a href="#cb36-4" aria-hidden="true" tabindex="-1"></a>zone <span class="ot"><-</span> <span class="fu">st_geometry</span>(dangkao) <span class="sc">%>%</span></span> +<span id="cb36-5"><a href="#cb36-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">st_centroid</span>() <span class="sc">%>%</span></span> +<span id="cb36-6"><a href="#cb36-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">st_buffer</span>(<span class="dv">30000</span>)</span> +<span id="cb36-7"><a href="#cb36-7" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(district))</span> +<span id="cb36-8"><a href="#cb36-8" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(zone, <span class="at">border =</span> <span class="st">"#F06292"</span>, <span class="at">lwd =</span> <span class="dv">2</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/intersect2-1.png" class="img-fluid" width="672"></p> +</div> +<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a>dist_z <span class="ot"><-</span> <span class="fu">st_intersection</span>(<span class="at">x =</span> district, <span class="at">y =</span> zone)</span> +<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(district))</span> +<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(dist_z), <span class="at">col=</span><span class="st">"#AF7AC5"</span>, <span class="at">border=</span><span class="st">"#F9E79F"</span>, <span class="at">add=</span>T)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/intersect2-2.png" class="img-fluid" width="672"></p> +</div> +<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(dist_z))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/intersect2-3.png" class="img-fluid" width="672"></p> +</div> +</div> +</section> +<section id="create-regular-grid" class="level3" data-number="3.6.6"> +<h3 data-number="3.6.6" class="anchored" data-anchor-id="create-regular-grid"><span class="header-section-number">3.6.6</span> Create regular grid</h3> +<p>The function <code>st_make_grid()</code> allows you to create regular grid. The function produce and object <code>sfc</code>, you must then use the function <code>st_sf()</code> to transform the object <code>sfc</code> into and object <code>sf</code>. During this transformation we add here a column of unique identifiers.</p> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a>grid <span class="ot"><-</span> <span class="fu">st_make_grid</span>(<span class="at">x =</span> district, <span class="at">cellsize =</span> <span class="dv">10000</span>)</span> +<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a>grid <span class="ot"><-</span> <span class="fu">st_sf</span>(<span class="at">ID =</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(grid), <span class="at">geom =</span> grid)</span> +<span id="cb39-3"><a href="#cb39-3" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb39-4"><a href="#cb39-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(grid), <span class="at">col =</span> <span class="st">"grey"</span>, <span class="at">border =</span> <span class="st">"white"</span>)</span> +<span id="cb39-5"><a href="#cb39-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(district), <span class="at">border =</span> <span class="st">"grey50"</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/grid-1.png" class="img-fluid" width="672"></p> +</div> +</div> +</section> +<section id="counting-points-in-a-polygon-in-a-grid-tile" class="level3" data-number="3.6.7"> +<h3 data-number="3.6.7" class="anchored" data-anchor-id="counting-points-in-a-polygon-in-a-grid-tile"><span class="header-section-number">3.6.7</span> Counting points in a polygon (in a grid tile)</h3> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a><span class="co"># selection of grid tiles that intersect the district</span></span> +<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb40-3"><a href="#cb40-3" aria-hidden="true" tabindex="-1"></a>inter <span class="ot"><-</span> <span class="fu">st_intersects</span>(grid, cambodia_dist, <span class="at">sparse =</span> <span class="cn">FALSE</span>)</span> +<span id="cb40-4"><a href="#cb40-4" aria-hidden="true" tabindex="-1"></a>grid <span class="ot"><-</span> grid[inter, ]</span> +<span id="cb40-5"><a href="#cb40-5" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb40-6"><a href="#cb40-6" aria-hidden="true" tabindex="-1"></a>case_cambodia <span class="ot"><-</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"cases"</span> , <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span> +<span id="cb40-7"><a href="#cb40-7" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(grid), <span class="at">col =</span> <span class="st">"grey"</span>, <span class="at">border =</span> <span class="st">"white"</span>)</span> +<span id="cb40-8"><a href="#cb40-8" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(case_cambodia), <span class="at">pch =</span> <span class="dv">20</span>, <span class="at">col =</span> <span class="st">"red"</span>, <span class="at">add =</span> <span class="cn">TRUE</span>, <span class="at">cex =</span> <span class="fl">0.8</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/intersect3.1-1.png" class="img-fluid" width="672"></p> +</div> +<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a>inter <span class="ot"><-</span> <span class="fu">st_intersects</span>(grid, case_cambodia, <span class="at">sparse =</span> <span class="cn">TRUE</span>)</span> +<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a><span class="fu">length</span>(inter)</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>[1] 1964</code></pre> +</div> +</div> +<p>Here we use the argument <code>sparse = TRUE</code>. The <strong>inter</strong> object is a list the length of the <strong>grid</strong> and each item in the list contain the index of the object items of <strong>cases</strong> and <strong>grid</strong> intersection.</p> +<p>For example <strong>grid tile</strong> 35th intersect with four <strong>cases</strong> 97, 138, 189, 522, 624, 696</p> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a>inter[<span class="dv">35</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>[[1]] +[1] 97 138 189 522 624 696</code></pre> +</div> +<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(grid[<span class="dv">35</span>, ]))</span> +<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(case_cambodia), <span class="at">add =</span> T)</span> +<span id="cb45-3"><a href="#cb45-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(case_cambodia[<span class="fu">c</span>(<span class="dv">97</span>, <span class="dv">138</span>, <span class="dv">189</span>, <span class="dv">522</span>, <span class="dv">624</span>, <span class="dv">696</span>), ]), </span> +<span id="cb45-4"><a href="#cb45-4" aria-hidden="true" tabindex="-1"></a> <span class="at">col =</span> <span class="st">"red"</span>, <span class="at">pch =</span> <span class="dv">19</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/intersect3.3-1.png" class="img-fluid" width="672"></p> +</div> +</div> +<p>To count number of <strong>case</strong>, simply go to the list and report length of the elements.</p> +<div class="cell"> +<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a>grid<span class="sc">$</span>nb_case <span class="ot"><-</span> <span class="fu">sapply</span>(<span class="at">X =</span> inter, <span class="at">FUN =</span> length) <span class="co"># create 'nb_case' column to store number of health centers in each grid tile </span></span> +<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(grid[<span class="st">"nb_case"</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/intersect3.4-1.png" class="img-fluid" width="672"></p> +</div> +</div> +</section> +<section id="aggregate-point-values-into-polygons" class="level3" data-number="3.6.8"> +<h3 data-number="3.6.8" class="anchored" data-anchor-id="aggregate-point-values-into-polygons"><span class="header-section-number">3.6.8</span> Aggregate point values into polygons</h3> +<p>In this example we import a csv file that contain data from a population grid. Once import we transform it <code>data.frame</code> into an object <code>sf</code>.</p> +<p>The objective is to aggregate the values id these points (the population contained in the “DENs†field) in the municipalities of the district.</p> +<div class="cell"> +<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a>pp_pop_raw <span class="ot"><-</span> <span class="fu">read.csv</span>(<span class="st">"data_cambodia/pp_pop_dens.csv"</span>) <span class="co"># import file</span></span> +<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a>pp_pop_raw<span class="sc">$</span>id <span class="ot"><-</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">nrow</span>(pp_pop_raw) <span class="co"># adding a unique identifier</span></span> +<span id="cb47-3"><a href="#cb47-3" aria-hidden="true" tabindex="-1"></a>pp_pop <span class="ot"><-</span> <span class="fu">st_as_sf</span>(pp_pop_raw, <span class="at">coords =</span> <span class="fu">c</span>(<span class="st">"X"</span>, <span class="st">"Y"</span>), <span class="at">crs =</span> <span class="dv">32648</span>) <span class="co"># Transform into object sf</span></span> +<span id="cb47-4"><a href="#cb47-4" aria-hidden="true" tabindex="-1"></a>pp_pop <span class="ot"><-</span> <span class="fu">st_transform</span>(pp_pop, <span class="fu">st_crs</span>(district)) <span class="co"># Transform projection</span></span> +<span id="cb47-5"><a href="#cb47-5" aria-hidden="true" tabindex="-1"></a>inter <span class="ot"><-</span> <span class="fu">st_intersection</span>(pp_pop, district) <span class="co"># Intersection</span></span> +<span id="cb47-6"><a href="#cb47-6" aria-hidden="true" tabindex="-1"></a>inter</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>Simple feature collection with 1295 features and 12 fields +Geometry type: POINT +Dimension: XY +Bounding box: xmin: 469177.5 ymin: 1263090 xmax: 505177.5 ymax: 1297090 +Projected CRS: WGS 84 / UTM zone 48N +First 10 features: + DENs id ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP +149 NA 149 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +150 NA 150 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +151 NA 151 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +186 NA 186 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +187 NA 187 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +188 NA 188 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +223 NA 223 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +224 NA 224 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +225 NA 225 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +226 3.400075 226 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 + Area.Km2. Status DENs.1 geometry +149 183.905 <4500km2 503.3958 POINT (469177.5 1267090) +150 183.905 <4500km2 503.3958 POINT (470177.5 1267090) +151 183.905 <4500km2 503.3958 POINT (471177.5 1267090) +186 183.905 <4500km2 503.3958 POINT (469177.5 1268090) +187 183.905 <4500km2 503.3958 POINT (470177.5 1268090) +188 183.905 <4500km2 503.3958 POINT (471177.5 1268090) +223 183.905 <4500km2 503.3958 POINT (469177.5 1269090) +224 183.905 <4500km2 503.3958 POINT (470177.5 1269090) +225 183.905 <4500km2 503.3958 POINT (471177.5 1269090) +226 183.905 <4500km2 503.3958 POINT (472177.5 1269090)</code></pre> +</div> +</div> +<p>By using the function <code>st_intersection()</code> we add to each point of the grid all the information on the municipality in which it is located.</p> +<p>We can then use the function <code>aggregate()</code> to aggregate the population by municipalities.</p> +<div class="cell"> +<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a>resultat <span class="ot"><-</span> <span class="fu">aggregate</span>(<span class="at">x =</span> <span class="fu">list</span>(<span class="at">pop_from_grid =</span> inter<span class="sc">$</span>DENs), </span> +<span id="cb49-2"><a href="#cb49-2" aria-hidden="true" tabindex="-1"></a> <span class="at">by =</span> <span class="fu">list</span>(<span class="at">ADM2_EN =</span> inter<span class="sc">$</span>ADM2_EN), </span> +<span id="cb49-3"><a href="#cb49-3" aria-hidden="true" tabindex="-1"></a> <span class="at">FUN =</span> <span class="st">"sum"</span>)</span> +<span id="cb49-4"><a href="#cb49-4" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(resultat)</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> ADM2_EN pop_from_grid +1 Angk Snuol NA +2 Chamkar Mon 10492.7159 +3 Chbar Ampov 1593.9593 +4 Chraoy Chongvar 1434.1785 +5 Dangkao 942.3595 +6 Doun Penh 10781.8026</code></pre> +</div> +</div> +<p>We can then create a new object with this result.</p> +<div class="cell"> +<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a>dist_result <span class="ot"><-</span> <span class="fu">merge</span>(district, resultat, <span class="at">by =</span> <span class="st">"ADM2_EN"</span>, <span class="at">all.x =</span> <span class="cn">TRUE</span>)</span> +<span id="cb51-2"><a href="#cb51-2" aria-hidden="true" tabindex="-1"></a>dist_result</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>Simple feature collection with 197 features and 11 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 +First 10 features: + ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP +1 Aek Phnum KH0205 Battambang KH02 41500 43916 85416 +2 Andoung Meas KH1601 Ratanak Kiri KH16 7336 7372 14708 +3 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 +4 Angkor Borei KH2101 Takeo KH21 26306 27168 53474 +5 Angkor Chey KH0701 Kampot KH07 42448 44865 87313 +6 Angkor Chum KH1701 Siemreap KH17 34269 34576 68845 +7 Angkor Thum KH1702 Siemreap KH17 13802 14392 28194 +8 Anlong Veaeng KH2201 Oddar Meanchey KH22 24122 23288 47410 +9 Aoral KH0504 Kampong Speu KH05 19874 19956 39830 +10 Ba Phnum KH1401 Prey Veng KH14 46562 49852 96414 + Area.Km2. Status DENs pop_from_grid geometry +1 1067.8638 <4500km2 79.98773 NA MULTIPOLYGON (((306568.1 14... +2 837.7064 <4500km2 17.55747 NA MULTIPOLYGON (((751459.2 15... +3 183.9050 <4500km2 503.39580 NA MULTIPOLYGON (((471954.3 12... +4 301.0502 <4500km2 177.62485 NA MULTIPOLYGON (((490048.2 12... +5 316.7576 <4500km2 275.64610 NA MULTIPOLYGON (((462702.2 12... +6 478.6988 <4500km2 143.81696 NA MULTIPOLYGON (((363642.5 15... +7 357.8890 <4500km2 78.77862 NA MULTIPOLYGON (((376584.4 15... +8 1533.5702 <4500km2 30.91479 NA MULTIPOLYGON (((404936.4 15... +9 2381.7084 <4500km2 16.72329 NA MULTIPOLYGON (((414000.6 13... +10 342.3439 <4500km2 281.62910 NA MULTIPOLYGON (((545045.4 12...</code></pre> +</div> +</div> +</section> +</section> +<section id="measurements" class="level2" data-number="3.7"> +<h2 data-number="3.7" class="anchored" data-anchor-id="measurements"><span class="header-section-number">3.7</span> Measurements</h2> +<section id="create-a-distance-matrix" class="level3" data-number="3.7.1"> +<h3 data-number="3.7.1" class="anchored" data-anchor-id="create-a-distance-matrix"><span class="header-section-number">3.7.1</span> Create a distance matrix</h3> +<p>If the dataset’s projection system is specified, the distance are expressed in the projection measurement unit (most often in meter)</p> +<div class="cell" data-nm="true"> +<div class="sourceCode cell-code" id="cb53"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb53-1"><a href="#cb53-1" aria-hidden="true" tabindex="-1"></a>mat <span class="ot"><-</span> <span class="fu">st_distance</span>(<span class="at">x =</span> dist_c, <span class="at">y =</span> dist_c)</span> +<span id="cb53-2"><a href="#cb53-2" aria-hidden="true" tabindex="-1"></a>mat[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>,<span class="dv">1</span><span class="sc">:</span><span class="dv">5</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>Units: [m] + [,1] [,2] [,3] [,4] [,5] +[1,] 0.0 425993.7 232592.12 298254.12 299106.92 +[2,] 425993.7 0.0 386367.88 414428.82 452431.87 +[3,] 232592.1 386367.9 0.00 67060.05 82853.88 +[4,] 298254.1 414428.8 67060.05 0.00 40553.15 +[5,] 299106.9 452431.9 82853.88 40553.15 0.00</code></pre> +</div> +</div> +</section> +<section id="calculate-routes" class="level3" data-number="3.7.2"> +<h3 data-number="3.7.2" class="anchored" data-anchor-id="calculate-routes"><span class="header-section-number">3.7.2</span> Calculate routes</h3> +<p><img src="img/logo_osrm.svg" align="right" width="120"> The package <code>osrm</code> <span class="citation" data-cites="R-osrm">(<a href="references.html#ref-R-osrm" role="doc-biblioref"><strong>R-osrm?</strong></a>)</span> acts as an interface R and the <a href="http://project-osrm.org/">OSRM</a> <span class="citation" data-cites="luxen-vetter-2011">(<a href="references.html#ref-luxen-vetter-2011" role="doc-biblioref"><strong>luxen-vetter-2011?</strong></a>)</span>. This package allows to calculate time and distance matrices, road routes, isochrones. The package uses the OSRM demo server by default. In case of intensive use <a href="https://github.com/Project-OSRM/osrm-backend#using-docker">it is strongly recommended to use your own instance of OSRM (with Docker)</a>.</p> +<section id="calculate-a-route" class="level4" data-number="3.7.2.1"> +<h4 data-number="3.7.2.1" class="anchored" data-anchor-id="calculate-a-route"><span class="header-section-number">3.7.2.1</span> Calculate a route</h4> +<p>The fonction <code>osrmRoute()</code> allows you to calculate routes.</p> +<div class="cell"> +<div class="sourceCode cell-code" id="cb55"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb55-1"><a href="#cb55-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(sf)</span> +<span id="cb55-2"><a href="#cb55-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(osrm)</span> +<span id="cb55-3"><a href="#cb55-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(maptiles)</span> +<span id="cb55-4"><a href="#cb55-4" aria-hidden="true" tabindex="-1"></a>district <span class="ot"><-</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>,<span class="at">layer =</span> <span class="st">"district"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span> +<span id="cb55-5"><a href="#cb55-5" aria-hidden="true" tabindex="-1"></a>district <span class="ot"><-</span> <span class="fu">st_transform</span>(district, <span class="dv">32648</span>)</span> +<span id="cb55-6"><a href="#cb55-6" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb55-7"><a href="#cb55-7" aria-hidden="true" tabindex="-1"></a>odongk <span class="ot"><-</span> district[district<span class="sc">$</span>ADM2_PCODE <span class="sc">==</span> <span class="st">"KH0505"</span>, ] <span class="co"># Itinerary between Odongk district and Toul Kouk</span></span> +<span id="cb55-8"><a href="#cb55-8" aria-hidden="true" tabindex="-1"></a>takmau <span class="ot"><-</span> district[district<span class="sc">$</span>ADM2_PCODE <span class="sc">==</span> <span class="st">"KH0811"</span>,]</span> +<span id="cb55-9"><a href="#cb55-9" aria-hidden="true" tabindex="-1"></a>route <span class="ot"><-</span> <span class="fu">osrmRoute</span>(<span class="at">src =</span> odongk, </span> +<span id="cb55-10"><a href="#cb55-10" aria-hidden="true" tabindex="-1"></a> <span class="at">dst =</span> takmau, </span> +<span id="cb55-11"><a href="#cb55-11" aria-hidden="true" tabindex="-1"></a> <span class="at">returnclass =</span> <span class="st">"sf"</span>)</span> +<span id="cb55-12"><a href="#cb55-12" aria-hidden="true" tabindex="-1"></a>osm <span class="ot"><-</span> <span class="fu">get_tiles</span>(route, <span class="at">crop =</span> <span class="cn">TRUE</span>)</span> +<span id="cb55-13"><a href="#cb55-13" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_tiles</span>(osm)</span> +<span id="cb55-14"><a href="#cb55-14" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(route), <span class="at">col =</span> <span class="st">"#b23a5f"</span>, <span class="at">lwd =</span> <span class="dv">6</span>, <span class="at">add =</span> T)</span> +<span id="cb55-15"><a href="#cb55-15" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(route), <span class="at">col =</span> <span class="st">"#eee0e5"</span>, <span class="at">lwd =</span> <span class="dv">1</span>, <span class="at">add =</span> T)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/osrmroute-1.png" class="img-fluid" width="288"></p> +</div> +</div> +</section> +<section id="calculation-of-a-time-matrix" class="level4" data-number="3.7.2.2"> +<h4 data-number="3.7.2.2" class="anchored" data-anchor-id="calculation-of-a-time-matrix"><span class="header-section-number">3.7.2.2</span> Calculation of a time matrix</h4> +<p>The function <code>osrmTable()</code> makes it possible to calculate matrices of distances or times by road.</p> +<p>In this example we calculate a time matrix between 2 addresses and health centers in Phnom Penh on foot.</p> +<div class="cell"> +<div class="sourceCode cell-code" id="cb56"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb56-1"><a href="#cb56-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(sf)</span> +<span id="cb56-2"><a href="#cb56-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidygeocoder)</span> +<span id="cb56-3"><a href="#cb56-3" aria-hidden="true" tabindex="-1"></a>hospital <span class="ot"><-</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>,<span class="at">layer=</span> <span class="st">"hospital"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span> +<span id="cb56-4"><a href="#cb56-4" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb56-5"><a href="#cb56-5" aria-hidden="true" tabindex="-1"></a>hospital_pp <span class="ot"><-</span> hospital[hospital<span class="sc">$</span>PCODE <span class="sc">==</span> <span class="st">"12"</span>, ] <span class="co"># Selection of health centers in Phnom Penh</span></span> +<span id="cb56-6"><a href="#cb56-6" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb56-7"><a href="#cb56-7" aria-hidden="true" tabindex="-1"></a>adresses <span class="ot"><-</span> <span class="fu">data.frame</span>(<span class="at">adr =</span> <span class="fu">c</span>(<span class="st">"Royal Palace Park, Phnom Penh Phnom, Cambodia"</span>,</span> +<span id="cb56-8"><a href="#cb56-8" aria-hidden="true" tabindex="-1"></a> <span class="st">"Wat Phnom Daun Penh, Phnom Penh, Cambodia"</span>)) <span class="co"># Geocoding of 2 addresses in Phnom Penh</span></span> +<span id="cb56-9"><a href="#cb56-9" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb56-10"><a href="#cb56-10" aria-hidden="true" tabindex="-1"></a>places <span class="ot"><-</span> tidygeocoder<span class="sc">::</span><span class="fu">geocode</span>(<span class="at">.tbl =</span> adresses,<span class="at">address =</span> adr)</span> +<span id="cb56-11"><a href="#cb56-11" aria-hidden="true" tabindex="-1"></a>places</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># A tibble: 2 × 3 + adr lat long + <chr> <dbl> <dbl> +1 Royal Palace Park, Phnom Penh Phnom, Cambodia 11.6 105. +2 Wat Phnom Daun Penh, Phnom Penh, Cambodia 11.6 105.</code></pre> +</div> +<div class="sourceCode cell-code" id="cb58"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Calculation of the distance matrix between the 2 addresses and the health center in Phnom Penh</span></span> +<span id="cb58-2"><a href="#cb58-2" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb58-3"><a href="#cb58-3" aria-hidden="true" tabindex="-1"></a>cal_mat <span class="ot"><-</span> <span class="fu">osrmTable</span>(<span class="at">src =</span> places[,<span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">3</span>,<span class="dv">2</span>)], </span> +<span id="cb58-4"><a href="#cb58-4" aria-hidden="true" tabindex="-1"></a> <span class="at">dst =</span> hospital_pp, </span> +<span id="cb58-5"><a href="#cb58-5" aria-hidden="true" tabindex="-1"></a> <span class="at">osrm.profile =</span> <span class="st">"foot"</span>)</span> +<span id="cb58-6"><a href="#cb58-6" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb58-7"><a href="#cb58-7" aria-hidden="true" tabindex="-1"></a>cal_mat<span class="sc">$</span>durations[<span class="dv">1</span><span class="sc">:</span><span class="dv">2</span>, <span class="dv">1</span><span class="sc">:</span><span class="dv">5</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> 684 685 686 687 691 +Royal Palace Park, Phnom Penh Phnom, Cambodia 56.1 71.9 64.2 40.4 76.5 +Wat Phnom Daun Penh, Phnom Penh, Cambodia 60.1 80.5 43.8 32.8 55.6</code></pre> +</div> +<div class="sourceCode cell-code" id="cb60"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb60-1"><a href="#cb60-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Which address has better accessibility to health center in Phnom Penh?</span></span> +<span id="cb60-2"><a href="#cb60-2" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb60-3"><a href="#cb60-3" aria-hidden="true" tabindex="-1"></a><span class="fu">boxplot</span>(<span class="fu">t</span>(cal_mat<span class="sc">$</span>durations[,]), <span class="at">cex.axis =</span> <span class="fl">0.7</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> +<div class="cell-output-display"> +<p><img src="03-vector_data_files/figure-html/osrmtable-1.png" class="img-fluid" width="768"></p> +</div> +</div> + + +</section> +</section> +</section> + +</main> <!-- /main --> +<script id="quarto-html-after-body" type="application/javascript"> +window.document.addEventListener("DOMContentLoaded", function (event) { + const icon = ""; + const anchorJS = new window.AnchorJS(); + anchorJS.options = { + placement: 'right', + icon: icon + }; + anchorJS.add('.anchored'); + const clipboard = new window.ClipboardJS('.code-copy-button', { + target: function(trigger) { + return trigger.previousElementSibling; + } + }); + clipboard.on('success', function(e) { + // button target + const button = e.trigger; + // don't keep focus + button.blur(); + // flash "checked" + button.classList.add('code-copy-button-checked'); + var currentTitle = button.getAttribute("title"); + button.setAttribute("title", "Copied!"); + setTimeout(function() { + button.setAttribute("title", currentTitle); + button.classList.remove('code-copy-button-checked'); + }, 1000); + // clear code selection + e.clearSelection(); + }); + function tippyHover(el, contentFn) { + const config = { + allowHTML: true, + content: contentFn, + maxWidth: 500, + delay: 100, + arrow: false, + appendTo: function(el) { + return el.parentElement; + }, + interactive: true, + interactiveBorder: 10, + theme: 'quarto', + placement: 'bottom-start' + }; + window.tippy(el, config); + } + const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]'); + for (var i=0; i<noterefs.length; i++) { + const ref = noterefs[i]; + tippyHover(ref, function() { + let href = ref.getAttribute('href'); + try { href = new URL(href).hash; } catch {} + const id = href.replace(/^#\/?/, ""); + const note = window.document.getElementById(id); + return note.innerHTML; + }); + } + var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]'); + for (var i=0; i<bibliorefs.length; i++) { + const ref = bibliorefs[i]; + const cites = ref.parentNode.getAttribute('data-cites').split(' '); + tippyHover(ref, function() { + var popup = window.document.createElement('div'); + cites.forEach(function(cite) { + var citeDiv = window.document.createElement('div'); + citeDiv.classList.add('hanging-indent'); + citeDiv.classList.add('csl-entry'); + var biblioDiv = window.document.getElementById('ref-' + cite); + if (biblioDiv) { + citeDiv.innerHTML = biblioDiv.innerHTML; + } + popup.appendChild(citeDiv); + }); + return popup.innerHTML; + }); + } + var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//); + var filterRegex = new RegExp('/' + window.location.host + '/'); + var isInternal = (href) => { + return filterRegex.test(href) || localhostRegex.test(href); + } + // Inspect non-navigation links and adorn them if external + var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)'); + for (var i=0; i<links.length; i++) { + const link = links[i]; + if (!isInternal(link.href)) { + // target, if specified + link.setAttribute("target", "_blank"); + } + } +}); +</script> +<nav class="page-navigation"> + <div class="nav-page nav-page-previous"> + <a href="./02-data_acquisition.html" class="pagination-link"> + <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">2</span> <span class="chapter-title">Data Acquisition</span></span> + </a> + </div> + <div class="nav-page nav-page-next"> + <a href="./references.html" class="pagination-link"> + <span class="nav-page-text">References</span> <i class="bi bi-arrow-right-short"></i> + </a> + </div> +</nav> +</div> <!-- /content --> +<footer class="footer"> + <div class="nav-footer"> + <div class="nav-footer-left">UMR 228 ESPACE-DEV</div> + <div class="nav-footer-right"><img src="img/ird_footer.png" height="50"></div> + </div> +</footer> + + + +</body></html> \ No newline at end of file diff --git a/public/03-vector_data_files/figure-html/aff1-1.png b/public/03-vector_data_files/figure-html/aff1-1.png new file mode 100644 index 0000000000000000000000000000000000000000..034b9705a9f2a4fd0f468f69fb2c6102c26223ce Binary files /dev/null and b/public/03-vector_data_files/figure-html/aff1-1.png differ diff --git a/public/03-vector_data_files/figure-html/aff2-1.png b/public/03-vector_data_files/figure-html/aff2-1.png new file mode 100644 index 0000000000000000000000000000000000000000..5cb689e4fcd0e44b8a46393a79467d7eaeeec3a1 Binary files /dev/null and b/public/03-vector_data_files/figure-html/aff2-1.png differ diff --git a/public/03-vector_data_files/figure-html/aggreg-1.png b/public/03-vector_data_files/figure-html/aggreg-1.png new file mode 100644 index 0000000000000000000000000000000000000000..052fc9742b1b74f5afbda7d866e4f67104d92be0 Binary files /dev/null and b/public/03-vector_data_files/figure-html/aggreg-1.png differ diff --git a/public/03-vector_data_files/figure-html/aggreg2-1.png b/public/03-vector_data_files/figure-html/aggreg2-1.png new file mode 100644 index 0000000000000000000000000000000000000000..1bcf216b870c19954a2c412a035cce164f747b14 Binary files /dev/null and b/public/03-vector_data_files/figure-html/aggreg2-1.png differ diff --git a/public/03-vector_data_files/figure-html/buffers-1.png b/public/03-vector_data_files/figure-html/buffers-1.png new file mode 100644 index 0000000000000000000000000000000000000000..5300f8a19d2c6e73925dc23df95100ad7fbaf881 Binary files /dev/null and b/public/03-vector_data_files/figure-html/buffers-1.png differ diff --git a/public/03-vector_data_files/figure-html/centroid-1.png b/public/03-vector_data_files/figure-html/centroid-1.png new file mode 100644 index 0000000000000000000000000000000000000000..d16703fb1e277479f54a9da8a0ccd72ee81d64e3 Binary files /dev/null and b/public/03-vector_data_files/figure-html/centroid-1.png differ diff --git a/public/03-vector_data_files/figure-html/grid-1.png b/public/03-vector_data_files/figure-html/grid-1.png new file mode 100644 index 0000000000000000000000000000000000000000..71ec7c8292e4486c694cc3128e7c681e66b9b402 Binary files /dev/null and b/public/03-vector_data_files/figure-html/grid-1.png differ diff --git a/public/03-vector_data_files/figure-html/intersect2-1.png b/public/03-vector_data_files/figure-html/intersect2-1.png new file mode 100644 index 0000000000000000000000000000000000000000..dfd59ed93312a188607f5abdd089b96ca2016c0c Binary files /dev/null and b/public/03-vector_data_files/figure-html/intersect2-1.png differ diff --git a/public/03-vector_data_files/figure-html/intersect2-2.png b/public/03-vector_data_files/figure-html/intersect2-2.png new file mode 100644 index 0000000000000000000000000000000000000000..112f3a1b2f993eb1086a6c2043dbe7a0c44bc85e Binary files /dev/null and b/public/03-vector_data_files/figure-html/intersect2-2.png differ diff --git a/public/03-vector_data_files/figure-html/intersect2-3.png b/public/03-vector_data_files/figure-html/intersect2-3.png new file mode 100644 index 0000000000000000000000000000000000000000..0df9e03ea26865fe48bb4d1e7057d23a1cebfda9 Binary files /dev/null and b/public/03-vector_data_files/figure-html/intersect2-3.png differ diff --git a/public/03-vector_data_files/figure-html/intersect3.1-1.png b/public/03-vector_data_files/figure-html/intersect3.1-1.png new file mode 100644 index 0000000000000000000000000000000000000000..26e70ecc3545e0d0469e4154f0db4ac581261f90 Binary files /dev/null and b/public/03-vector_data_files/figure-html/intersect3.1-1.png differ diff --git a/public/03-vector_data_files/figure-html/intersect3.3-1.png b/public/03-vector_data_files/figure-html/intersect3.3-1.png new file mode 100644 index 0000000000000000000000000000000000000000..f8b97ce2b5013d3ce2dc7dff4fc452c06e32bc83 Binary files /dev/null and b/public/03-vector_data_files/figure-html/intersect3.3-1.png differ diff --git a/public/03-vector_data_files/figure-html/intersect3.4-1.png b/public/03-vector_data_files/figure-html/intersect3.4-1.png new file mode 100644 index 0000000000000000000000000000000000000000..4311668be74f68cfb8ce88f1f409354e366bd806 Binary files /dev/null and b/public/03-vector_data_files/figure-html/intersect3.4-1.png differ diff --git a/public/03-vector_data_files/figure-html/intersects2-1.png b/public/03-vector_data_files/figure-html/intersects2-1.png new file mode 100644 index 0000000000000000000000000000000000000000..5f7fc379836df91882baf17f81440c0b903a80e0 Binary files /dev/null and b/public/03-vector_data_files/figure-html/intersects2-1.png differ diff --git a/public/03-vector_data_files/figure-html/osrmroute-1.png b/public/03-vector_data_files/figure-html/osrmroute-1.png new file mode 100644 index 0000000000000000000000000000000000000000..767d506177df9f0cd07ca6dfaeb42ed6ce987003 Binary files /dev/null and b/public/03-vector_data_files/figure-html/osrmroute-1.png differ diff --git a/public/03-vector_data_files/figure-html/osrmtable-1.png b/public/03-vector_data_files/figure-html/osrmtable-1.png new file mode 100644 index 0000000000000000000000000000000000000000..cfda8a805bc509bcb9913a58a38844a9eed0e11d Binary files /dev/null and b/public/03-vector_data_files/figure-html/osrmtable-1.png differ diff --git a/public/03-vector_data_files/figure-html/proj2-1.png b/public/03-vector_data_files/figure-html/proj2-1.png new file mode 100644 index 0000000000000000000000000000000000000000..f21c3b9c64a036998b927284e7cd88fb4fece360 Binary files /dev/null and b/public/03-vector_data_files/figure-html/proj2-1.png differ diff --git a/public/03-vector_data_files/figure-html/proj2-2.png b/public/03-vector_data_files/figure-html/proj2-2.png new file mode 100644 index 0000000000000000000000000000000000000000..ff1cebde5f246a92c37547ee52eb20ca9e2dc260 Binary files /dev/null and b/public/03-vector_data_files/figure-html/proj2-2.png differ diff --git a/public/03-vector_data_files/figure-html/st_intersparse-1.png b/public/03-vector_data_files/figure-html/st_intersparse-1.png new file mode 100644 index 0000000000000000000000000000000000000000..50ca94ca60b31cd01beef73223c1607053bb9b52 Binary files /dev/null and b/public/03-vector_data_files/figure-html/st_intersparse-1.png differ diff --git a/public/03-vector_data_files/figure-html/within-1.png b/public/03-vector_data_files/figure-html/within-1.png new file mode 100644 index 0000000000000000000000000000000000000000..7a3d788f0e17f68cd3df74fe234596df7af204e5 Binary files /dev/null and b/public/03-vector_data_files/figure-html/within-1.png differ diff --git a/public/img/logo_osrm.svg b/public/img/logo_osrm.svg new file mode 100644 index 0000000000000000000000000000000000000000..aed0ce0cb256f8453f61c14a558a810b0954d161 --- /dev/null +++ b/public/img/logo_osrm.svg @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="350px" height="118px" viewBox="0 0 350 118" enable-background="new 0 0 350 118" xml:space="preserve"> +<g id="Guides" display="none"> +</g> +<g id="_x31_2_Col_Grid" display="none" opacity="0.1" enable-background="new "> +</g> +<g id="Layer_3" display="none"> +</g> +<g id="Layer_3_copy" display="none"> +</g> +<g id="Layer_3_copy_2" display="none"> +</g> +<g id="Layer_3_copy_3" display="none"> +</g> +<g id="Layer_3_copy_4" display="none"> +</g> +<g id="design"> + <linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="4.3718" y1="47.8668" x2="345.8111" y2="47.8668"> + <stop offset="0" style="stop-color:#005591"/> + <stop offset="1" style="stop-color:#572B7A"/> + </linearGradient> + <path fill="url(#SVGID_1_)" d="M344.2,4.7c-1.1-1.1-2.4-1.7-4-1.7l-21.5,0.1c-2.7-0.1-4.5,1-5.5,3.4L304.3,31L298,13.5l-2.6-7 c-1-2.4-2.8-3.5-5.6-3.5h-28c-1.5,0-2.9,0.5-4,1.6c-1.1,1.1-1.6,2.4-1.6,4v78.4c0,1.5,0.6,2.8,1.7,3.9c1.1,1.1,2.4,1.7,3.9,1.7 c1.5,0,2.9-0.5,4-1.6c1.1-1.1,1.6-2.4,1.6-4V40.6l17.5,48.5c0.9,2.3,2.7,3.4,5.2,3.4c2.6,0,4.3-1.1,5.3-3.4l8.9-24.5l7.7,21.3 l0.1-0.1l1.2,3.3c0.4,1,1.1,1.9,2.2,2.6c1,0.7,2.1,1,3.3,1h21.5c1.6,0,2.9-0.6,4-1.7c1-1.1,1.6-2.4,1.6-3.9V8.6 C345.8,7.1,345.3,5.8,344.2,4.7z M290.2,70.1L270,14.3h16.1l2.4,6.7l0,0l9.7,26.9L290.2,70.1z M334.6,81.5h-12l-1-2.9l0,0l0,0 l-3.6-10c0,0,0,0,0-0.1l-7.5-20.7l12.1-33.5h12.1V81.5z M49.2,25.5c-6.2,0-11.5,2.2-15.9,6.6c-4.4,4.4-6.6,9.7-6.6,15.9 c0,6.2,2.2,11.5,6.6,15.9s9.7,6.6,15.9,6.6c6.2,0,11.5-2.2,15.9-6.6s6.6-9.7,6.6-15.9c0-6.2-2.2-11.5-6.6-15.9 C60.7,27.6,55.4,25.5,49.2,25.5z M57.1,55.8c-2.2,2.2-4.8,3.3-7.9,3.3c-3.1,0-5.7-1.1-7.9-3.3C39.1,53.6,38,51,38,47.9 c0-3.1,1.1-5.7,3.3-7.9c2.2-2.2,4.8-3.3,7.9-3.3c3.1,0,5.7,1.1,7.9,3.3c2.2,2.2,3.3,4.8,3.3,7.9C60.4,51,59.3,53.6,57.1,55.8z M49.2,3C36.8,3,26.3,7.4,17.5,16.2C8.7,24.9,4.4,35.5,4.4,47.9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8,109.1,182.8,109.8z M181.5,109.8c0-0.5-0.1-0.9-0.2-1.3 s-0.4-0.8-0.6-1.1c-0.3-0.3-0.6-0.6-1-0.7c-0.4-0.2-0.8-0.3-1.3-0.3c-0.5,0-0.9,0.1-1.3,0.3c-0.4,0.2-0.7,0.4-1,0.7 c-0.3,0.3-0.5,0.7-0.6,1.1c-0.2,0.4-0.2,0.9-0.2,1.3c0,0.5,0.1,0.9,0.2,1.3c0.2,0.4,0.4,0.8,0.6,1.1c0.3,0.3,0.6,0.5,1,0.7 c0.4,0.2,0.8,0.3,1.3,0.3s0.9-0.1,1.3-0.3s0.7-0.4,1-0.7c0.3-0.3,0.5-0.7,0.6-1.1C181.4,110.7,181.5,110.3,181.5,109.8z"/> + <path fill="#FF930E" d="M192.8,114.3c-0.6,0-1-0.1-1.5-0.3c-0.4-0.2-0.8-0.4-1-0.8c-0.3-0.3-0.5-0.7-0.6-1.1 c-0.1-0.4-0.2-0.8-0.2-1.3v-5.4h1.2v5.3c0,0.3,0,0.6,0.1,0.9c0.1,0.3,0.2,0.5,0.4,0.8c0.2,0.2,0.4,0.4,0.6,0.5 c0.3,0.1,0.6,0.2,1,0.2c0.4,0,0.7-0.1,1-0.2c0.3-0.1,0.5-0.3,0.7-0.5c0.2-0.2,0.3-0.5,0.4-0.8c0.1-0.3,0.1-0.6,0.1-0.9v-5.3h1.2 v5.4c0,0.4-0.1,0.9-0.2,1.3c-0.1,0.4-0.3,0.8-0.6,1.1c-0.3,0.3-0.6,0.6-1,0.8C193.8,114.2,193.4,114.3,192.8,114.3z"/> + <path fill="#FF930E" d="M206.2,114.1H205v-7.5h-2.7v-1h6.6v1h-2.7V114.1z"/> + <path fill="#FF930E" d="M216.4,114.1h-1.2v-8.5h1.2V114.1z"/> + <path fill="#FF930E" d="M229.6,112.4L229.6,112.4l0-6.8h1.2v8.5h-1.5l-4.5-6.9h0v6.9h-1.2v-8.5h1.5L229.6,112.4z"/> + <path fill="#FF930E" d="M244.5,107.3c-0.3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0.7,1.4-0.9 c0.6-0.2,1.2-0.3,1.8-0.3c0.3,0,0.6,0,0.9,0.1c0.3,0.1,0.6,0.1,0.9,0.3c0.3,0.1,0.5,0.2,0.7,0.4c0.2,0.2,0.4,0.4,0.6,0.6l-0.9,0.7 c-0.2-0.3-0.5-0.5-0.9-0.7c-0.4-0.2-0.8-0.3-1.2-0.3c-0.5,0-0.9,0.1-1.3,0.3c-0.4,0.2-0.7,0.4-1,0.7c-0.3,0.3-0.5,0.7-0.6,1.1 c-0.2,0.4-0.2,0.9-0.2,1.3c0,0.5,0.1,0.9,0.2,1.3c0.1,0.4,0.4,0.8,0.6,1.1s0.6,0.5,1,0.7c0.4,0.2,0.8,0.3,1.3,0.3 c0.5,0,0.9-0.1,1.3-0.3c0.4-0.2,0.7-0.5,1-0.8L297.5,112.7z"/> + <path fill="#FF930E" d="M303.9,105.6h1.2v3.6h4.3v-3.6h1.2v8.5h-1.2v-3.9h-4.3v3.9h-1.2V105.6z"/> + <path fill="#FF930E" d="M319,114.1h-1.2v-8.5h1.2V114.1z"/> + <path fill="#FF930E" d="M332.2,112.4L332.2,112.4l0-6.8h1.2v8.5h-1.5l-4.5-6.9h0v6.9h-1.2v-8.5h1.5L332.2,112.4z"/> + <path fill="#FF930E" d="M341.8,113h4.4v1.1h-5.6v-8.5h5.4v1h-4.3v2.5h4v1h-4V113z"/> + </g> +</g> +<g id="illusrations"> +</g> +</svg> \ No newline at end of file diff --git a/public/search.json b/public/search.json index 23c3cccfc7821c0a2788024809d9cc87ac45fed1..20687309dccaa689b25356ae912b0bd37d46e29f 100644 --- a/public/search.json +++ b/public/search.json @@ -68,5 +68,54 @@ "title": "2 Data Acquisition", "section": "2.5 Digitization", "text": "2.5 Digitization\nThe package mapedit (Appelhans, Russell, and Busetto 2020) allows you to digitize base map directly in R. Although it can be practical in some cases, in package cannot replace the functionalities of a GIS for important digitization tasks.\n\n\n\nGif taken from mapedit website\n\n\n\n\n\n\nAgafonkin, Vladimir. 2015. “Leaflet Javascript Libary.â€\n\n\nAppelhans, Tim, Florian Detsch, Christoph Reudenbach, and Stefan Woellauer. 2022. “Mapview: Interactive Viewing of Spatial Data in r.†https://CRAN.R-project.org/package=mapview.\n\n\nAppelhans, Tim, Kenton Russell, and Lorenzo Busetto. 2020. “Mapedit: Interactive Editing of Spatial Data in r.†https://CRAN.R-project.org/package=mapedit.\n\n\nCambon, Jesse, Diego Hernangómez, Christopher Belanger, and Daniel Possenriede. 2021. “Tidygeocoder: An r Package for Geocoding†6: 3544. https://doi.org/10.21105/joss.03544.\n\n\nCheng, Joe, Bhaskar Karambelkar, and Yihui Xie. 2022. “Leaflet: Create Interactive Web Maps with the JavaScript ’Leaflet’ Library.†https://CRAN.R-project.org/package=leaflet.\n\n\nGilardi, Andrea, and Robin Lovelace. 2021. “Osmextract: Download and Import Open Street Map Data Extracts.†https://CRAN.R-project.org/package=osmextract.\n\n\nGiraud, Timothée. 2021. “Maptiles: Download and Display Map Tiles.†https://CRAN.R-project.org/package=maptiles.\n\n\nGombin, Joel, and Paul-Antoine Chevalier. 2022. “banR: R Client for the BAN API.â€\n\n\nPadgham, Mark, Bob Rudis, Robin Lovelace, and Maëlle Salmon. 2017. “Osmdata†2. https://doi.org/10.21105/joss.00305." + }, + { + "objectID": "03-vector_data.html", + "href": "03-vector_data.html", + "title": "3 Vector Data", + "section": "", + "text": "The st_read() and st_write() function are used to import and export many types of files. The following lines import the administrative data in district level layer located in the cambodia.gpkg geopackage file.\n\nlibrary(sf)\n\ndistrict = st_read(\"data_cambodia/cambodia.gpkg\", layer = \"district\") #import district data\n\nReading layer `district' from data source \n `/home/lucas/Documents/GitHub/rspatial-for-onehealth/data_cambodia/cambodia.gpkg' \n using driver `GPKG'\nSimple feature collection with 197 features and 10 fields\nGeometry type: MULTIPOLYGON\nDimension: XY\nBounding box: xmin: 211534.7 ymin: 1149105 xmax: 784612.1 ymax: 1625495\nProjected CRS: WGS 84 / UTM zone 48N\n\n\nThe following lines export the district object to a data folder in geopackage and shapefile format.\n\nst_write(obj = district, dsn = \"data_cambodia/district.gpkg\", delete_layer = TRUE)\n\nDeleting layer `district' using driver `GPKG'\nWriting layer `district' to data source \n `data_cambodia/district.gpkg' using driver `GPKG'\nWriting 197 features with 10 fields and geometry type Multi Polygon.\n\nst_write(obj = district, \"data_cambodia/district.shp\", layer_options = \"ENCODING=UTF-8\", delete_layer = TRUE)\n\nDeleting layer `district' using driver `ESRI Shapefile'\nWriting layer `district' to data source \n `data_cambodia/district.shp' using driver `ESRI Shapefile'\noptions: ENCODING=UTF-8 \nWriting 197 features with 10 fields and geometry type Multi Polygon." + }, + { + "objectID": "03-vector_data.html#display", + "href": "03-vector_data.html#display", + "title": "3 Vector Data", + "section": "3.2 Display", + "text": "3.2 Display\nPreview of the variables via the function head() and plot().\n\nhead(district)\n\nSimple feature collection with 6 features and 10 fields\nGeometry type: MULTIPOLYGON\nDimension: XY\nBounding box: xmin: 300266.9 ymin: 1180566 xmax: 767313.9 ymax: 1563861\nProjected CRS: WGS 84 / UTM zone 48N\n ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP Area.Km2.\n1 Aek Phnum KH0205 Battambang KH02 41500 43916 85416 1067.8638\n2 Andoung Meas KH1601 Ratanak Kiri KH16 7336 7372 14708 837.7064\n3 Angk Snuol KH0808 Kandal KH08 45436 47141 92577 183.9050\n4 Angkor Borei KH2101 Takeo KH21 26306 27168 53474 301.0502\n5 Angkor Chey KH0701 Kampot KH07 42448 44865 87313 316.7576\n6 Angkor Chum KH1701 Siemreap KH17 34269 34576 68845 478.6988\n Status DENs geom\n1 <4500km2 79.98773 MULTIPOLYGON (((306568.1 14...\n2 <4500km2 17.55747 MULTIPOLYGON (((751459.2 15...\n3 <4500km2 503.39580 MULTIPOLYGON (((471954.3 12...\n4 <4500km2 177.62485 MULTIPOLYGON (((490048.2 12...\n5 <4500km2 275.64610 MULTIPOLYGON (((462702.2 12...\n6 <4500km2 143.81696 MULTIPOLYGON (((363642.5 15...\n\nplot(district)\n\n\n\n\nfor Geometry display only.\n\nplot(st_geometry(district))" + }, + { + "objectID": "03-vector_data.html#coordinate-systems", + "href": "03-vector_data.html#coordinate-systems", + "title": "3 Vector Data", + "section": "3.3 Coordinate systems", + "text": "3.3 Coordinate systems\n\n3.3.1 Look up the coordinate system of an object\nThe function st_crs() makes it possible to consult the system of coordinates used and object sf.\n\nst_crs(district)\n\nCoordinate Reference System:\n User input: WGS 84 / UTM zone 48N \n wkt:\nPROJCRS[\"WGS 84 / UTM zone 48N\",\n BASEGEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n ID[\"EPSG\",4326]],\n CONVERSION[\"UTM zone 48N\",\n METHOD[\"Transverse Mercator\",\n ID[\"EPSG\",9807]],\n PARAMETER[\"Latitude of natural origin\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8801]],\n PARAMETER[\"Longitude of natural origin\",105,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8802]],\n PARAMETER[\"Scale factor at natural origin\",0.9996,\n SCALEUNIT[\"unity\",1],\n ID[\"EPSG\",8805]],\n PARAMETER[\"False easting\",500000,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8806]],\n PARAMETER[\"False northing\",0,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8807]]],\n CS[Cartesian,2],\n AXIS[\"(E)\",east,\n ORDER[1],\n LENGTHUNIT[\"metre\",1]],\n AXIS[\"(N)\",north,\n ORDER[2],\n LENGTHUNIT[\"metre\",1]],\n USAGE[\n SCOPE[\"Engineering survey, topographic mapping.\"],\n AREA[\"Between 102°E and 108°E, northern hemisphere between equator and 84°N, onshore and offshore. Cambodia. China. Indonesia. Laos. Malaysia - West Malaysia. Mongolia. Russian Federation. Singapore. Thailand. Vietnam.\"],\n BBOX[0,102,84,108]],\n ID[\"EPSG\",32648]]\n\n\n\n\n3.3.2 Changing the coordinate system of an object\nThe function st_transform() allows to change the coordinate system of an sf object, to re-project it.\n\nplot(st_geometry(district))\ntitle(\"WGS 84 / UTM zone 48N\")\n\n\n\ndist_reproj <- st_transform(district, \"epsg:4326\")\nplot(st_geometry(dist_reproj))\ntitle(\"WGS84\")\n\n\n\n\nThe Spatial Reference site provides reference for a large number of coordinate systems." + }, + { + "objectID": "03-vector_data.html#selection-by-attributes", + "href": "03-vector_data.html#selection-by-attributes", + "title": "3 Vector Data", + "section": "3.4 Selection by attributes", + "text": "3.4 Selection by attributes\nThe object sf are data.frame, so you can select their rows and columns in the same way as data.frame.\n\n# row Selection\ndistrict[1:2, ]\n\nSimple feature collection with 2 features and 10 fields\nGeometry type: MULTIPOLYGON\nDimension: XY\nBounding box: xmin: 300266.9 ymin: 1449408 xmax: 767313.9 ymax: 1563861\nProjected CRS: WGS 84 / UTM zone 48N\n ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP Area.Km2.\n1 Aek Phnum KH0205 Battambang KH02 41500 43916 85416 1067.8638\n2 Andoung Meas KH1601 Ratanak Kiri KH16 7336 7372 14708 837.7064\n Status DENs geom\n1 <4500km2 79.98773 MULTIPOLYGON (((306568.1 14...\n2 <4500km2 17.55747 MULTIPOLYGON (((751459.2 15...\n\ndistrict[district$ADM1_EN == \"Phnom Penh\", ]\n\nSimple feature collection with 12 features and 10 fields\nGeometry type: MULTIPOLYGON\nDimension: XY\nBounding box: xmin: 468677.5 ymin: 1262590 xmax: 505351.9 ymax: 1297419\nProjected CRS: WGS 84 / UTM zone 48N\nFirst 10 features:\n ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP\n29 Chamkar Mon KH1201 Phnom Penh KH12 52278 54478 106756\n31 Chbar Ampov KH1212 Phnom Penh KH12 64816 68243 133059\n43 Chraoy Chongvar KH1210 Phnom Penh KH12 30920 31087 62007\n48 Dangkao KH1205 Phnom Penh KH12 46999 48525 95524\n50 Doun Penh KH1202 Phnom Penh KH12 33844 36471 70315\n93 Mean Chey KH1206 Phnom Penh KH12 68381 70366 138747\n117 Praek Pnov KH1211 Phnom Penh KH12 27566 27698 55264\n118 Prampir Meakkakra KH1203 Phnom Penh KH12 31091 33687 64778\n133 Pur SenChey KH1209 Phnom Penh KH12 95050 109297 204347\n141 Russey Keo KH1207 Phnom Penh KH12 67357 68419 135776\n Area.Km2. Status DENs geom\n29 11.049600 <4500km2 9661.5265 MULTIPOLYGON (((494709.4 12...\n31 86.780498 <4500km2 1533.2823 MULTIPOLYGON (((498855.3 12...\n43 85.609156 <4500km2 724.3034 MULTIPOLYGON (((491161.3 12...\n48 113.774833 <4500km2 839.5881 MULTIPOLYGON (((489191.1 12...\n50 7.734808 <4500km2 9090.7234 MULTIPOLYGON (((492447.1 12...\n93 28.998026 <4500km2 4784.7051 MULTIPOLYGON (((491068.2 12...\n117 115.384300 <4500km2 478.9560 MULTIPOLYGON (((481483.3 12...\n118 2.224892 <4500km2 29115.1253 MULTIPOLYGON (((491067.6 12...\n133 148.357984 <4500km2 1377.3913 MULTIPOLYGON (((479078.8 12...\n141 23.381517 <4500km2 5806.9800 MULTIPOLYGON (((490264.8 12...\n\n# column selection\ndistrict[district$ADM1_EN == \"Phnom Penh\", 1:4] \n\nSimple feature collection with 12 features and 4 fields\nGeometry type: MULTIPOLYGON\nDimension: XY\nBounding box: xmin: 468677.5 ymin: 1262590 xmax: 505351.9 ymax: 1297419\nProjected CRS: WGS 84 / UTM zone 48N\nFirst 10 features:\n ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE\n29 Chamkar Mon KH1201 Phnom Penh KH12\n31 Chbar Ampov KH1212 Phnom Penh KH12\n43 Chraoy Chongvar KH1210 Phnom Penh KH12\n48 Dangkao KH1205 Phnom Penh KH12\n50 Doun Penh KH1202 Phnom Penh KH12\n93 Mean Chey KH1206 Phnom Penh KH12\n117 Praek Pnov KH1211 Phnom Penh KH12\n118 Prampir Meakkakra KH1203 Phnom Penh KH12\n133 Pur SenChey KH1209 Phnom Penh KH12\n141 Russey Keo KH1207 Phnom Penh KH12\n geom\n29 MULTIPOLYGON (((494709.4 12...\n31 MULTIPOLYGON (((498855.3 12...\n43 MULTIPOLYGON (((491161.3 12...\n48 MULTIPOLYGON (((489191.1 12...\n50 MULTIPOLYGON (((492447.1 12...\n93 MULTIPOLYGON (((491068.2 12...\n117 MULTIPOLYGON (((481483.3 12...\n118 MULTIPOLYGON (((491067.6 12...\n133 MULTIPOLYGON (((479078.8 12...\n141 MULTIPOLYGON (((490264.8 12..." + }, + { + "objectID": "03-vector_data.html#spatial-selection", + "href": "03-vector_data.html#spatial-selection", + "title": "3 Vector Data", + "section": "3.5 Spatial selection", + "text": "3.5 Spatial selection\n\n3.5.1 Intersections\nSelection of roads that are intersecting dangkao district\n\nroad <- st_read(\"data_cambodia/cambodia.gpkg\", layer = \"road\", quiet = TRUE)\ndangkao <- district[district$ADM2_EN == \"Dangkao\", ]\ninter <- st_intersects(x = road, y = dangkao, sparse = FALSE)\nhead(inter)\n\n [,1]\n[1,] TRUE\n[2,] TRUE\n[3,] TRUE\n[4,] TRUE\n[5,] TRUE\n[6,] TRUE\n\ndim(inter)\n\n[1] 6 1\n\n\nThe inter object is a matrix which indicates for each of element of the road object (6 elements) whether it intersects each elements the dangkao object (1 element). The dimension of the matrix is therefore indeed 6 rows * 1 column. Note the use of the parameter sparse = FALSE here. It is then possible to create a column from this object:\n\nroad$intersect_dangkao <- inter\nplot(st_geometry(dangkao), col = \"lightblue\")\nplot(st_geometry(road), add = TRUE)\nplot(st_geometry(road[road$intersect_dangkao, ]),\n col = \"tomato\", lwd = 1.5, add = TRUE)\n\n\n\n\n\n3.5.1.1 Difference between sparse = TRUE and sparse = FALSE\n\n\n\n\n\n\nsparse = TRUE\n\n\ninter <- st_intersects(x = grid, y = pt, sparse = TRUE)\ninter\n\nSparse geometry binary predicate list of length 4, where the predicate\nwas `intersects'\n 1: (empty)\n 2: 6, 7\n 3: 1, 4\n 4: 2, 3, 5, 8\n\n\n\nsparse = FALSE\n\n\ninter <- st_intersects(x = grid, y = pt, sparse = FALSE)\nrownames(inter) <- grid$id\ncolnames(inter) <- pt$id\ninter\n\n a b c d e f g h\n1 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE\n2 FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE\n3 TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE\n4 FALSE TRUE TRUE FALSE TRUE FALSE FALSE TRUE\n\n\n\n\n\n3.5.2 Contains / Within\nSelection of roads contained in the municipality of Dangkao. The function st_within() works like the function st_intersects()\n\nroad$within_dangkao <- st_within(road, dangkao, sparse = FALSE)\nplot(st_geometry(dangkao), col = \"lightblue\")\nplot(st_geometry(road), add = TRUE)\n\n\n\nplot(st_geometry(road[road$within_dangkao, ]), col = \"tomato\",\n lwd = 2, add = TRUE)" + }, + { + "objectID": "03-vector_data.html#operation-of-geometries", + "href": "03-vector_data.html#operation-of-geometries", + "title": "3 Vector Data", + "section": "3.6 Operation of geometries", + "text": "3.6 Operation of geometries\n\n3.6.1 Extract centroids\n\ndist_c <- st_centroid(district)\nplot(st_geometry(district))\nplot(st_geometry(dist_c), add = TRUE, cex = 1.2, col = \"red\", pch = 20)\n\n\n\n\n\n\n3.6.2 Aggregate polygons\n\ncambodia_dist <- st_union(district) \nplot(st_geometry(district), col = \"lightblue\")\nplot(st_geometry(cambodia_dist), add = TRUE, lwd = 2, border = \"red\")\n\n\n\n\n\n\n3.6.3 Aggregate polygons based on a variable\n\ndist_union <- aggregate(x = district[,c(\"T_POP\")],\n by = list(STATUT = district$Status),\n FUN = \"sum\")\nplot(dist_union)\n\n\n\n\n\n\n3.6.4 Create a buffer zone\n\ndangkao_buffer <- st_buffer(x = dangkao, dist = 1000)\nplot(st_geometry(dangkao_buffer), col = \"#E8DAEF\", lwd=2, border = \"#6C3483\")\nplot(st_geometry(dangkao), add = TRUE, lwd = 2)\n\n\n\n\n\n\n3.6.5 Making an intersection\nBy using the function st_intersection() we will cut one layer by another.\n\nlibrary(magrittr)\n# creation of a buffer zone around the centroid of the municipality of Dangkao district\n# using the pipe\nzone <- st_geometry(dangkao) %>%\n st_centroid() %>%\n st_buffer(30000)\nplot(st_geometry(district))\nplot(zone, border = \"#F06292\", lwd = 2, add = TRUE)\n\n\n\ndist_z <- st_intersection(x = district, y = zone)\nplot(st_geometry(district))\nplot(st_geometry(dist_z), col=\"#AF7AC5\", border=\"#F9E79F\", add=T)\n\n\n\nplot(st_geometry(dist_z))\n\n\n\n\n\n\n3.6.6 Create regular grid\nThe function st_make_grid() allows you to create regular grid. The function produce and object sfc, you must then use the function st_sf() to transform the object sfc into and object sf. During this transformation we add here a column of unique identifiers.\n\ngrid <- st_make_grid(x = district, cellsize = 10000)\ngrid <- st_sf(ID = 1:length(grid), geom = grid)\n\nplot(st_geometry(grid), col = \"grey\", border = \"white\")\nplot(st_geometry(district), border = \"grey50\", add = TRUE)\n\n\n\n\n\n\n3.6.7 Counting points in a polygon (in a grid tile)\n\n# selection of grid tiles that intersect the district\n\ninter <- st_intersects(grid, cambodia_dist, sparse = FALSE)\ngrid <- grid[inter, ]\n\ncase_cambodia <- st_read(\"data_cambodia/cambodia.gpkg\", layer = \"cases\" , quiet = TRUE)\nplot(st_geometry(grid), col = \"grey\", border = \"white\")\nplot(st_geometry(case_cambodia), pch = 20, col = \"red\", add = TRUE, cex = 0.8)\n\n\n\ninter <- st_intersects(grid, case_cambodia, sparse = TRUE)\nlength(inter)\n\n[1] 1964\n\n\nHere we use the argument sparse = TRUE. The inter object is a list the length of the grid and each item in the list contain the index of the object items of cases and grid intersection.\nFor example grid tile 35th intersect with four cases 97, 138, 189, 522, 624, 696\n\ninter[35]\n\n[[1]]\n[1] 97 138 189 522 624 696\n\nplot(st_geometry(grid[35, ]))\nplot(st_geometry(case_cambodia), add = T)\nplot(st_geometry(case_cambodia[c(97, 138, 189, 522, 624, 696), ]), \n col = \"red\", pch = 19, add = TRUE)\n\n\n\n\nTo count number of case, simply go to the list and report length of the elements.\n\ngrid$nb_case <- sapply(X = inter, FUN = length) # create 'nb_case' column to store number of health centers in each grid tile \nplot(grid[\"nb_case\"])\n\n\n\n\n\n\n3.6.8 Aggregate point values into polygons\nIn this example we import a csv file that contain data from a population grid. Once import we transform it data.frame into an object sf.\nThe objective is to aggregate the values id these points (the population contained in the “DENs†field) in the municipalities of the district.\n\npp_pop_raw <- read.csv(\"data_cambodia/pp_pop_dens.csv\") # import file\npp_pop_raw$id <- 1:nrow(pp_pop_raw) # adding a unique identifier\npp_pop <- st_as_sf(pp_pop_raw, coords = c(\"X\", \"Y\"), crs = 32648) # Transform into object sf\npp_pop <- st_transform(pp_pop, st_crs(district)) # Transform projection\ninter <- st_intersection(pp_pop, district) # Intersection\ninter\n\nSimple feature collection with 1295 features and 12 fields\nGeometry type: POINT\nDimension: XY\nBounding box: xmin: 469177.5 ymin: 1263090 xmax: 505177.5 ymax: 1297090\nProjected CRS: WGS 84 / UTM zone 48N\nFirst 10 features:\n DENs id ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP\n149 NA 149 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n150 NA 150 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n151 NA 151 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n186 NA 186 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n187 NA 187 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n188 NA 188 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n223 NA 223 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n224 NA 224 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n225 NA 225 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n226 3.400075 226 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n Area.Km2. Status DENs.1 geometry\n149 183.905 <4500km2 503.3958 POINT (469177.5 1267090)\n150 183.905 <4500km2 503.3958 POINT (470177.5 1267090)\n151 183.905 <4500km2 503.3958 POINT (471177.5 1267090)\n186 183.905 <4500km2 503.3958 POINT (469177.5 1268090)\n187 183.905 <4500km2 503.3958 POINT (470177.5 1268090)\n188 183.905 <4500km2 503.3958 POINT (471177.5 1268090)\n223 183.905 <4500km2 503.3958 POINT (469177.5 1269090)\n224 183.905 <4500km2 503.3958 POINT (470177.5 1269090)\n225 183.905 <4500km2 503.3958 POINT (471177.5 1269090)\n226 183.905 <4500km2 503.3958 POINT (472177.5 1269090)\n\n\nBy using the function st_intersection() we add to each point of the grid all the information on the municipality in which it is located.\nWe can then use the function aggregate() to aggregate the population by municipalities.\n\nresultat <- aggregate(x = list(pop_from_grid = inter$DENs), \n by = list(ADM2_EN = inter$ADM2_EN), \n FUN = \"sum\")\nhead(resultat)\n\n ADM2_EN pop_from_grid\n1 Angk Snuol NA\n2 Chamkar Mon 10492.7159\n3 Chbar Ampov 1593.9593\n4 Chraoy Chongvar 1434.1785\n5 Dangkao 942.3595\n6 Doun Penh 10781.8026\n\n\nWe can then create a new object with this result.\n\ndist_result <- merge(district, resultat, by = \"ADM2_EN\", all.x = TRUE)\ndist_result\n\nSimple feature collection with 197 features and 11 fields\nGeometry type: MULTIPOLYGON\nDimension: XY\nBounding box: xmin: 211534.7 ymin: 1149105 xmax: 784612.1 ymax: 1625495\nProjected CRS: WGS 84 / UTM zone 48N\nFirst 10 features:\n ADM2_EN ADM2_PCODE ADM1_EN ADM1_PCODE Male Female T_POP\n1 Aek Phnum KH0205 Battambang KH02 41500 43916 85416\n2 Andoung Meas KH1601 Ratanak Kiri KH16 7336 7372 14708\n3 Angk Snuol KH0808 Kandal KH08 45436 47141 92577\n4 Angkor Borei KH2101 Takeo KH21 26306 27168 53474\n5 Angkor Chey KH0701 Kampot KH07 42448 44865 87313\n6 Angkor Chum KH1701 Siemreap KH17 34269 34576 68845\n7 Angkor Thum KH1702 Siemreap KH17 13802 14392 28194\n8 Anlong Veaeng KH2201 Oddar Meanchey KH22 24122 23288 47410\n9 Aoral KH0504 Kampong Speu KH05 19874 19956 39830\n10 Ba Phnum KH1401 Prey Veng KH14 46562 49852 96414\n Area.Km2. Status DENs pop_from_grid geometry\n1 1067.8638 <4500km2 79.98773 NA MULTIPOLYGON (((306568.1 14...\n2 837.7064 <4500km2 17.55747 NA MULTIPOLYGON (((751459.2 15...\n3 183.9050 <4500km2 503.39580 NA MULTIPOLYGON (((471954.3 12...\n4 301.0502 <4500km2 177.62485 NA MULTIPOLYGON (((490048.2 12...\n5 316.7576 <4500km2 275.64610 NA MULTIPOLYGON (((462702.2 12...\n6 478.6988 <4500km2 143.81696 NA MULTIPOLYGON (((363642.5 15...\n7 357.8890 <4500km2 78.77862 NA MULTIPOLYGON (((376584.4 15...\n8 1533.5702 <4500km2 30.91479 NA MULTIPOLYGON (((404936.4 15...\n9 2381.7084 <4500km2 16.72329 NA MULTIPOLYGON (((414000.6 13...\n10 342.3439 <4500km2 281.62910 NA MULTIPOLYGON (((545045.4 12..." + }, + { + "objectID": "03-vector_data.html#measurements", + "href": "03-vector_data.html#measurements", + "title": "3 Vector Data", + "section": "3.7 Measurements", + "text": "3.7 Measurements\n\n3.7.1 Create a distance matrix\nIf the dataset’s projection system is specified, the distance are expressed in the projection measurement unit (most often in meter)\n\nmat <- st_distance(x = dist_c, y = dist_c)\nmat[1:5,1:5]\n\nUnits: [m]\n [,1] [,2] [,3] [,4] [,5]\n[1,] 0.0 425993.7 232592.12 298254.12 299106.92\n[2,] 425993.7 0.0 386367.88 414428.82 452431.87\n[3,] 232592.1 386367.9 0.00 67060.05 82853.88\n[4,] 298254.1 414428.8 67060.05 0.00 40553.15\n[5,] 299106.9 452431.9 82853.88 40553.15 0.00\n\n\n\n\n3.7.2 Calculate routes\n The package osrm (R-osrm?) acts as an interface R and the OSRM (luxen-vetter-2011?). This package allows to calculate time and distance matrices, road routes, isochrones. The package uses the OSRM demo server by default. In case of intensive use it is strongly recommended to use your own instance of OSRM (with Docker).\n\n3.7.2.1 Calculate a route\nThe fonction osrmRoute() allows you to calculate routes.\n\nlibrary(sf)\nlibrary(osrm)\nlibrary(maptiles)\ndistrict <- st_read(\"data_cambodia/cambodia.gpkg\",layer = \"district\", quiet = TRUE)\ndistrict <- st_transform(district, 32648)\n\nodongk <- district[district$ADM2_PCODE == \"KH0505\", ] # Itinerary between Odongk district and Toul Kouk\ntakmau <- district[district$ADM2_PCODE == \"KH0811\",]\nroute <- osrmRoute(src = odongk, \n dst = takmau, \n returnclass = \"sf\")\nosm <- get_tiles(route, crop = TRUE)\nplot_tiles(osm)\nplot(st_geometry(route), col = \"#b23a5f\", lwd = 6, add = T)\nplot(st_geometry(route), col = \"#eee0e5\", lwd = 1, add = T)\n\n\n\n\n\n\n3.7.2.2 Calculation of a time matrix\nThe function osrmTable() makes it possible to calculate matrices of distances or times by road.\nIn this example we calculate a time matrix between 2 addresses and health centers in Phnom Penh on foot.\n\nlibrary(sf)\nlibrary(tidygeocoder)\nhospital <- st_read(\"data_cambodia/cambodia.gpkg\",layer= \"hospital\", quiet = TRUE)\n\nhospital_pp <- hospital[hospital$PCODE == \"12\", ] # Selection of health centers in Phnom Penh\n\nadresses <- data.frame(adr = c(\"Royal Palace Park, Phnom Penh Phnom, Cambodia\",\n \"Wat Phnom Daun Penh, Phnom Penh, Cambodia\")) # Geocoding of 2 addresses in Phnom Penh\n\nplaces <- tidygeocoder::geocode(.tbl = adresses,address = adr)\nplaces\n\n# A tibble: 2 × 3\n adr lat long\n <chr> <dbl> <dbl>\n1 Royal Palace Park, Phnom Penh Phnom, Cambodia 11.6 105.\n2 Wat Phnom Daun Penh, Phnom Penh, Cambodia 11.6 105.\n\n# Calculation of the distance matrix between the 2 addresses and the health center in Phnom Penh\n\ncal_mat <- osrmTable(src = places[,c(1,3,2)], \n dst = hospital_pp, \n osrm.profile = \"foot\")\n\ncal_mat$durations[1:2, 1:5]\n\n 684 685 686 687 691\nRoyal Palace Park, Phnom Penh Phnom, Cambodia 56.1 71.9 64.2 40.4 76.5\nWat Phnom Daun Penh, Phnom Penh, Cambodia 60.1 80.5 43.8 32.8 55.6\n\n# Which address has better accessibility to health center in Phnom Penh?\n\nboxplot(t(cal_mat$durations[,]), cex.axis = 0.7)" } ] \ No newline at end of file