Skip to content
Snippets Groups Projects
02-data_acquisition.html 57.1 KiB
Newer Older
lucas.longour_ird.fr's avatar
lucas.longour_ird.fr committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
<!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 - 2&nbsp; Data Acquisition</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 */
div.csl-bib-body { }
div.csl-entry {
  clear: both;
}
.hanging div.csl-entry {
  margin-left:2em;
  text-indent:-2em;
}
div.csl-left-margin {
  min-width:2em;
  float:left;
}
div.csl-right-inline {
  margin-left:2em;
  padding-left:1em;
}
div.csl-indent {
  margin-left: 2em;
}
</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="./01-introduction.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>
<script src="site_libs/htmlwidgets-1.5.4/htmlwidgets.js"></script>
<script src="site_libs/jquery-1.12.4/jquery.min.js"></script>
<link href="site_libs/leaflet-1.3.1/leaflet.css" rel="stylesheet">
<script src="site_libs/leaflet-1.3.1/leaflet.js"></script>
<link href="site_libs/leafletfix-1.0.0/leafletfix.css" rel="stylesheet">
<script src="site_libs/proj4-2.6.2/proj4.min.js"></script>
<script src="site_libs/Proj4Leaflet-1.0.1/proj4leaflet.js"></script>
<link href="site_libs/rstudio_leaflet-1.3.1/rstudio_leaflet.css" rel="stylesheet">
<script src="site_libs/leaflet-binding-2.1.1/leaflet.js"></script>
<script src="site_libs/leaflet-providers-1.9.0/leaflet-providers_1.9.0.js"></script>
<script src="site_libs/leaflet-providers-plugin-2.1.1/leaflet-providers-plugin.js"></script>
<link href="site_libs/HomeButton-0.0.1/home-button.css" rel="stylesheet">
<script src="site_libs/HomeButton-0.0.1/home-button.js"></script>
<script src="site_libs/HomeButton-0.0.1/easy-button-src.min.js"></script>
<script src="site_libs/clipboard-0.0.1/setClipboardText.js"></script>
<link href="site_libs/mapviewCSS-0.0.1/mapview-popup.css" rel="stylesheet">
<link href="site_libs/mapviewCSS-0.0.1/mapview.css" rel="stylesheet">


<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">2</span>&nbsp; <span class="chapter-title">Data Acquisition</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>&nbsp; <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 active"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Data Acquisition</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="#import-from-lat-long-file" id="toc-import-from-lat-long-file" class="nav-link active" data-scroll-target="#import-from-lat-long-file"> <span class="header-section-number">2.1</span> Import from lat / long file</a></li>
  <li><a href="#online-databases" id="toc-online-databases" class="nav-link" data-scroll-target="#online-databases"> <span class="header-section-number">2.2</span> Online databases</a></li>
  <li><a href="#openstreetmap" id="toc-openstreetmap" class="nav-link" data-scroll-target="#openstreetmap"> <span class="header-section-number">2.3</span> OpenStreetMap</a>
  <ul class="collapse">
  <li><a href="#display-and-interactive-map" id="toc-display-and-interactive-map" class="nav-link" data-scroll-target="#display-and-interactive-map"> <span class="header-section-number">2.3.1</span> Display and interactive map</a></li>
  <li><a href="#import-basemaps" id="toc-import-basemaps" class="nav-link" data-scroll-target="#import-basemaps"> <span class="header-section-number">2.3.2</span> Import basemaps</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">2</span>&nbsp; <span class="chapter-title">Data Acquisition</span></h1>
</div>



<div class="quarto-title-meta">

    
    
  </div>
  

</header>

<section id="import-from-lat-long-file" class="level2" data-number="2.1">
<h2 data-number="2.1" class="anchored" data-anchor-id="import-from-lat-long-file"><span class="header-section-number">2.1</span> Import from lat / long file</h2>
<p>The function <code>st_as_sf()</code> makes it possible to transform a <code>data.frame</code> container of geographic coordinates into an object <code>sf</code>. Here we use the <code>data.frame</code> <code>places2</code> created in the previous point.</p>
<div class="cell" data-nm="true">
<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>place_sf <span class="ot">&lt;-</span> <span class="fu">st_as_sf</span>(<span class="fu">read.csv</span>(<span class="st">"data_cambodia/adress.csv"</span>), <span class="at">coords =</span> <span class="fu">c</span>(<span class="st">"long"</span>, <span class="st">"lat"</span>), <span class="at">crs =</span> <span class="dv">4326</span>)</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>place_sf</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre class="code-out"><code>Simple feature collection with 2 features and 1 field
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 104.8443 ymin: 11.54366 xmax: 104.9047 ymax: 11.55349
Geodetic CRS:  WGS 84
                                                 address
1 Phnom Penh International Airport, Phnom Penh, Cambodia
2 Khmer Soviet Friendship Hospital, Phnom Penh, Cambodia
                   geometry
1 POINT (104.8443 11.55349)
2 POINT (104.9047 11.54366)</code></pre>
</div>
</div>
<p>To crate a <code>sf</code> POINT type object with only one pair of coordinate (WGS84, longitude=0.5, latitude = 45.5) :</p>
<div class="cell" data-nm="true">
<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">library</span>(sf)</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>test_point <span class="ot">&lt;-</span> <span class="fu">st_as_sf</span>(<span class="fu">data.frame</span>(<span class="at">x =</span> <span class="fl">0.5</span>, <span class="at">y =</span> <span class="fl">45.5</span>), <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">4326</span>)</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>test_point</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 1 feature and 0 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 0.5 ymin: 45.5 xmax: 0.5 ymax: 45.5
Geodetic CRS:  WGS 84
          geometry
1 POINT (0.5 45.5)</code></pre>
</div>
</div>
<p>We can display this object <code>sf</code> on an <a href="https://www.openstreetmap.org/">OpenStreetMap</a> basesmap with the package maptiles <code>maptiles</code> <span class="citation" data-cites="maptiles">(<a href="references.html#ref-maptiles" role="doc-biblioref">Giraud 2021</a>)</span>.</p>
<div class="cell" data-nm="true">
<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">library</span>(maptiles)</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>osm <span class="ot">&lt;-</span> <span class="fu">get_tiles</span>(<span class="at">x =</span> place_sf, <span class="at">zoom =</span> <span class="dv">12</span>)</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_tiles</span>(osm)</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">st_geometry</span>(place_sf), <span class="at">pch =</span> <span class="dv">2</span>, <span class="at">cex =</span> <span class="dv">2</span>, <span class="at">col =</span> <span class="st">"red"</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="02-data_acquisition_files/figure-html/display_sf-1.png" class="img-fluid" width="788"></p>
</div>
</div>
</section>
<section id="online-databases" class="level2" data-number="2.2">
<h2 data-number="2.2" class="anchored" data-anchor-id="online-databases"><span class="header-section-number">2.2</span> Online databases</h2>
</section>
<section id="openstreetmap" class="level2" data-number="2.3">
<h2 data-number="2.3" class="anchored" data-anchor-id="openstreetmap"><span class="header-section-number">2.3</span> OpenStreetMap</h2>
<div style="float: right">
<p><img src="img/Openstreetmap_logo.svg" width="150px" padding="1em"></p>
</div>
<p><a href="https://www.openstreetmap.org" target="_blank">OpenStreetMap (OSM)</a> is a participatory mapping project that aim s to buil a free geographic database on a global scale. OpenStreetMap lets you view, edit and use geographic data around the world.</p>
<p><strong>Terms of use</strong></p>
<blockquote class="blockquote">
<p>OpenStreetMap is open data : you are free to use it for ant purpose as long as you credit OpenStreetMap and its contributers. If you modify or rely data in any way, you may distribute the result only under the same license. (…)</p>
</blockquote>
<p><strong>Contributors</strong></p>
<blockquote class="blockquote">
<p>(…) Our contributors incloude enthusiastic mapmakers, GIS professional, engineers running OSM servers, humanitarians mapping disaster-stricken areas and many mmore.(…)</p>
</blockquote>
<section id="display-and-interactive-map" class="level3" data-number="2.3.1">
<h3 data-number="2.3.1" class="anchored" data-anchor-id="display-and-interactive-map"><span class="header-section-number">2.3.1</span> Display and interactive map</h3>
<p>The two main packages that allow to display as interactive map based on OSM are <code>leaflet</code> <span class="citation" data-cites="leaflet">(<a href="references.html#ref-leaflet" role="doc-biblioref">Cheng, Karambelkar, and Xie 2022</a>)</span> and <code>mapview</code> <span class="citation" data-cites="mapview">(<a href="references.html#ref-mapview" role="doc-biblioref">Appelhans et al. 2022</a>)</span>.</p>
<section id="leaflet" class="level4" data-number="2.3.1.1">
<h4 data-number="2.3.1.1" class="anchored" data-anchor-id="leaflet"><span class="header-section-number">2.3.1.1</span> <code>leaflet</code></h4>
<p><img src="img/logo_leaflet.png" align="right" width="200"> <code>leaflet</code> uses the javascript library Leaflet <span class="citation" data-cites="JS-Leaflet">(<a href="references.html#ref-JS-Leaflet" role="doc-biblioref">Agafonkin 2015</a>)</span> to create interactive maps.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(sf)</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(leaflet)</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>district <span class="ot">&lt;-</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"district"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>hospital <span class="ot">&lt;-</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"hospital"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>banan <span class="ot">&lt;-</span> district[district<span class="sc">$</span>ADM2_PCODE <span class="sc">==</span> <span class="st">"KH0201"</span>, ]     <span class="co">#Select one district (Banan district: KH0201)</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>health_banan <span class="ot">&lt;-</span> hospital[hospital<span class="sc">$</span>DCODE <span class="sc">==</span> <span class="st">"201"</span>, ]      <span class="co">#Select Health centers in Banan</span></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a>banan <span class="ot">&lt;-</span> <span class="fu">st_transform</span>(banan, <span class="dv">4326</span>)                       <span class="co">#Transform coordinate system to WGS84</span></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a>health_banan <span class="ot">&lt;-</span> <span class="fu">st_transform</span>(health_banan, <span class="dv">4326</span>)</span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a>banan_map <span class="ot">&lt;-</span> <span class="fu">leaflet</span>(banan) <span class="sc">%&gt;%</span>                          <span class="co">#Create interactive map</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">addTiles</span>() <span class="sc">%&gt;%</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">addPolygons</span>() <span class="sc">%&gt;%</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">addMarkers</span>(<span class="at">data =</span> health_banan)</span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a>banan_map</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div id="htmlwidget-a788e0ad1bb5305cd165" style="width:100%;height:464px;" class="leaflet html-widget"></div>
<script type="application/json" data-for="htmlwidget-a788e0ad1bb5305cd165">{"x":{"options":{"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}}},"calls":[{"method":"addTiles","args":["https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",null,null,{"minZoom":0,"maxZoom":18,"tileSize":256,"subdomains":"abc","errorTileUrl":"","tms":false,"noWrap":false,"zoomOffset":0,"zoomReverse":false,"opacity":1,"zIndex":1,"detectRetina":false,"attribution":"&copy; <a href=\"https://openstreetmap.org\">OpenStreetMap<\/a> contributors, <a href=\"https://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA<\/a>"}]},{"method":"addPolygons","args":[[[[{"lng":[102.905700684,102.995117187,102.998901367,103.003295898,103.009094238,103.014099121,103.019104004,103.024291992,103.02947998,103.034912109,103.039123535,103.042907715,103.040100098,103.038330078,103.038696289,103.039123535,103.039916992,103.040710449,103.041320801,103.042907715,103.046081543,103.047485352,103.051696777,103.0546875,103.05871582,103.063720703,103.068115234,103.071899414,103.072692871,103.073486328,103.076904297,103.080688477,103.081481934,103.082092285,103.082275391,103.083129883,103.083679199,103.08392334,103.084106445,103.084899902,103.090515137,103.095703125,103.105712891,103.114929199,103.125488281,103.12890625,103.131286621,103.134094238,103.136901855,103.141113281,103.142883301,103.143676758,103.144897461,103.145874023,103.146911621,103.150878906,103.153930664,103.156677246,103.160095215,103.163513184,103.167724609,103.172119141,103.176330566,103.180908203,103.186096191,103.190490723,103.190307617,103.1875,103.18371582,103.181274414,103.177490234,103.174499512,103.172912598,103.172485352,103.173095703,103.171081543,103.167724609,103.167907715,103.16607666,103.162109375,103.163879395,103.160705566,103.158081055,103.160888672,103.165283203,103.167907715,103.169494629,103.17388916,103.177124023,103.183105469,103.18951416,103.193115234,103.19732666,103.200500488,103.201293945,103.202270508,103.202880859,103.204711914,103.205505371,103.206298828,103.207275391,103.208312988,103.209899902,103.221313477,103.219726562,103.221130371,103.22052002,103.22088623,103.200927734,103.167297363,103.147888184,103.116516113,103.079284668,103.044128418,103.040100098,103.030273437,103.044311523,103.040100098,103.022521973,103.002502441,102.996276855,102.98248291,102.968688965,102.957092285,102.959106445,102.938476562,102.861694336,102.84552002,102.829101562,102.922302246,102.926696777,102.926696777,102.925109863,102.923278809,102.921508789,102.919494629,102.917480469,102.915283203,102.913085937,102.911315918,102.908691406,102.90612793,102.905273437,102.904296875,102.903686523,102.90447998,102.905700684],"lat":[13.1356811520001,13.134887695,13.134887695,13.134887695,13.1347045900001,13.1347045900001,13.134887695,13.134887695,13.135070801,13.134887695,13.134887695,13.1333007810001,13.128479004,13.12512207,13.121704102,13.118286133,13.1145019530001,13.1102905270001,13.1068725590001,13.104125977,13.1036987300001,13.1010742190001,13.0988769530001,13.097473145,13.0957031250001,13.094299316,13.094299316,13.094299316,13.090698242,13.086730957,13.086303711,13.086303711,13.07989502,13.0759277340001,13.07232666,13.0682983400001,13.0651245120001,13.0612792970001,13.0568847660001,13.051330566,13.051086426,13.051330566,13.052124023,13.0524902340001,13.0524902340001,13.047729492,13.045471191,13.0471191410001,13.0493164060001,13.0515136720001,13.046691895,13.04309082,13.0380859370001,13.034484863,13.03112793,13.030883789,13.032287598,13.0336914060001,13.0349121090001,13.034484863,13.034301758,13.034301758,13.034301758,13.034301758,13.034301758,13.033081055,13.028930664,13.0263061520001,13.027893066,13.0258789060001,13.026489258,13.0250854490001,13.022094727,13.0184936520001,13.014709473,13.0109252930001,13.011291504,13.014709473,13.0170898440001,13.0170898440001,13.01348877,13.0114746090001,13.009094238,13.0070800780001,13.006713867,13.004699707,13.0004882810001,12.9995117190001,12.9996948240001,12.9995117190001,12.999328613,12.999084473,12.9982910160001,12.9882812500001,12.983276367,12.978088379,12.974914551,12.970092773,12.965881348,12.962524414,12.955871582,12.951721191,12.947875977,12.9509277340001,12.931518555,12.9274902340001,12.9110717770001,12.8925170900001,12.8701171870001,12.832092285,12.8225097660001,12.8082885740001,12.7885131840001,12.77130127,12.7706909180001,12.839904785,12.8615112300001,12.8679199220001,12.8942871090001,12.92388916,12.929504395,12.933898926,12.9384765620001,12.9420776370001,12.949523926,12.9520874020001,12.965698242,13.0017089840001,13.037902832,13.0739135740001,13.075500488,13.078674316,13.0827026370001,13.0858764650001,13.088500977,13.0922851560001,13.0966796870001,13.1002807620001,13.1035156250001,13.107299805,13.110717773,13.116516113,13.120910645,13.124084473,13.127319336,13.13092041,13.1356811520001]}]]],null,null,{"interactive":true,"className":"","stroke":true,"color":"#03F","weight":5,"opacity":0.5,"fill":true,"fillColor":"#03F","fillOpacity":0.2,"smoothFactor":1,"noClip":false},null,null,null,{"interactive":false,"permanent":false,"direction":"auto","opacity":1,"offset":[0,0],"textsize":"10px","textOnly":false,"className":"","sticky":true},null]},{"method":"addMarkers","args":[[12.9967916898305,12.9567883731443,12.8720155591406,13.0282719817933,12.9670658006501,13.059247470427],[103.160327966176,103.145195121288,103.103397307151,103.097624250892,103.051274915643,103.060133124932],null,null,null,{"interactive":true,"draggable":false,"keyboard":true,"title":"","alt":"","zIndexOffset":0,"opacity":1,"riseOnHover":false,"riseOffset":250},null,null,null,null,null,{"interactive":false,"permanent":false,"direction":"auto","opacity":1,"offset":[0,0],"textsize":"10px","textOnly":false,"className":"","sticky":true},null]}],"limits":{"lat":[12.7706909180001,13.1356811520001],"lng":[102.829101562,103.221313477]}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<div class="callout-note callout callout-style-simple no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<p>Website of <code>leaflet</code><br>
<a href="https://rstudio.github.io/leaflet/">Leaflet for R</a></p>
</div>
</div>
</div>
</section>
<section id="mapview" class="level4" data-number="2.3.1.2">
<h4 data-number="2.3.1.2" class="anchored" data-anchor-id="mapview"><span class="header-section-number">2.3.1.2</span> <code>mapview</code></h4>
<p><img src="img/logo_mapview.gif" align="right" width="150"> <code>mapview</code> relies on <code>leaflet</code> to create interactive maps, its use is easier and its documentation is a bit dense.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(mapview)</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mapview</span>(banan) <span class="sc">+</span> <span class="fu">mapview</span>(health_banan)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">

<div id="htmlwidget-a69edeea7880baad2383" style="width:100%;height:464px;" class="leaflet html-widget"></div>
<script type="application/json" data-for="htmlwidget-a69edeea7880baad2383">{"x":{"options":{"minZoom":1,"maxZoom":52,"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}},"preferCanvas":false,"bounceAtZoomLimits":false,"maxBounds":[[[-90,-370]],[[90,370]]]},"calls":[{"method":"addProviderTiles","args":["CartoDB.Positron","CartoDB.Positron","CartoDB.Positron",{"errorTileUrl":"","noWrap":false,"detectRetina":false,"pane":"tilePane"}]},{"method":"addProviderTiles","args":["CartoDB.DarkMatter","CartoDB.DarkMatter","CartoDB.DarkMatter",{"errorTileUrl":"","noWrap":false,"detectRetina":false,"pane":"tilePane"}]},{"method":"addProviderTiles","args":["OpenStreetMap","OpenStreetMap","OpenStreetMap",{"errorTileUrl":"","noWrap":false,"detectRetina":false,"pane":"tilePane"}]},{"method":"addProviderTiles","args":["Esri.WorldImagery","Esri.WorldImagery","Esri.WorldImagery",{"errorTileUrl":"","noWrap":false,"detectRetina":false,"pane":"tilePane"}]},{"method":"addProviderTiles","args":["OpenTopoMap","OpenTopoMap","OpenTopoMap",{"errorTileUrl":"","noWrap":false,"detectRetina":false,"pane":"tilePane"}]},{"method":"createMapPane","args":["polygon",420]},{"method":"addPolygons","args":[[[[{"lng":[102.905700684,102.995117187,102.998901367,103.003295898,103.009094238,103.014099121,103.019104004,103.024291992,103.02947998,103.034912109,103.039123535,103.042907715,103.040100098,103.038330078,103.038696289,103.039123535,103.039916992,103.040710449,103.041320801,103.042907715,103.046081543,103.047485352,103.051696777,103.0546875,103.05871582,103.063720703,103.068115234,103.071899414,103.072692871,103.073486328,103.076904297,103.080688477,103.081481934,103.082092285,103.082275391,103.083129883,103.083679199,103.08392334,103.084106445,103.084899902,103.090515137,103.095703125,103.105712891,103.114929199,103.125488281,103.12890625,103.131286621,103.134094238,103.136901855,103.141113281,103.142883301,103.143676758,103.144897461,103.145874023,103.146911621,103.150878906,103.153930664,103.156677246,103.160095215,103.163513184,103.167724609,103.172119141,103.176330566,103.180908203,103.186096191,103.190490723,103.190307617,103.1875,103.18371582,103.181274414,103.177490234,103.174499512,103.172912598,103.172485352,103.173095703,103.171081543,103.167724609,103.167907715,103.16607666,103.162109375,103.163879395,103.160705566,103.158081055,103.160888672,103.165283203,103.167907715,103.169494629,103.17388916,103.177124023,103.183105469,103.18951416,103.193115234,103.19732666,103.200500488,103.201293945,103.202270508,103.202880859,103.204711914,103.205505371,103.206298828,103.207275391,103.208312988,103.209899902,103.221313477,103.219726562,103.221130371,103.22052002,103.22088623,103.200927734,103.167297363,103.147888184,103.116516113,103.079284668,103.044128418,103.040100098,103.030273437,103.044311523,103.040100098,103.022521973,103.002502441,102.996276855,102.98248291,102.968688965,102.957092285,102.959106445,102.938476562,102.861694336,102.84552002,102.829101562,102.922302246,102.926696777,102.926696777,102.925109863,102.923278809,102.921508789,102.919494629,102.917480469,102.915283203,102.913085937,102.911315918,102.908691406,102.90612793,102.905273437,102.904296875,102.903686523,102.90447998,102.905700684],"lat":[13.1356811520001,13.134887695,13.134887695,13.134887695,13.1347045900001,13.1347045900001,13.134887695,13.134887695,13.135070801,13.134887695,13.134887695,13.1333007810001,13.128479004,13.12512207,13.121704102,13.118286133,13.1145019530001,13.1102905270001,13.1068725590001,13.104125977,13.1036987300001,13.1010742190001,13.0988769530001,13.097473145,13.0957031250001,13.094299316,13.094299316,13.094299316,13.090698242,13.086730957,13.086303711,13.086303711,13.07989502,13.0759277340001,13.07232666,13.0682983400001,13.0651245120001,13.0612792970001,13.0568847660001,13.051330566,13.051086426,13.051330566,13.052124023,13.0524902340001,13.0524902340001,13.047729492,13.045471191,13.0471191410001,13.0493164060001,13.0515136720001,13.046691895,13.04309082,13.0380859370001,13.034484863,13.03112793,13.030883789,13.032287598,13.0336914060001,13.0349121090001,13.034484863,13.034301758,13.034301758,13.034301758,13.034301758,13.034301758,13.033081055,13.028930664,13.0263061520001,13.027893066,13.0258789060001,13.026489258,13.0250854490001,13.022094727,13.0184936520001,13.014709473,13.0109252930001,13.011291504,13.014709473,13.0170898440001,13.0170898440001,13.01348877,13.0114746090001,13.009094238,13.0070800780001,13.006713867,13.004699707,13.0004882810001,12.9995117190001,12.9996948240001,12.9995117190001,12.999328613,12.999084473,12.9982910160001,12.9882812500001,12.983276367,12.978088379,12.974914551,12.970092773,12.965881348,12.962524414,12.955871582,12.951721191,12.947875977,12.9509277340001,12.931518555,12.9274902340001,12.9110717770001,12.8925170900001,12.8701171870001,12.832092285,12.8225097660001,12.8082885740001,12.7885131840001,12.77130127,12.7706909180001,12.839904785,12.8615112300001,12.8679199220001,12.8942871090001,12.92388916,12.929504395,12.933898926,12.9384765620001,12.9420776370001,12.949523926,12.9520874020001,12.965698242,13.0017089840001,13.037902832,13.0739135740001,13.075500488,13.078674316,13.0827026370001,13.0858764650001,13.088500977,13.0922851560001,13.0966796870001,13.1002807620001,13.1035156250001,13.107299805,13.110717773,13.116516113,13.120910645,13.124084473,13.127319336,13.13092041,13.1356811520001]}]]],null,"banan",{"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}},"pane":"polygon","stroke":true,"color":"#333333","weight":0.5,"opacity":0.9,"fill":true,"fillColor":"#6666FF","fillOpacity":0.6,"smoothFactor":1,"noClip":false},"<div class='scrollableContainer'><table class=mapview-popup id='popup'><tr class='coord'><td><\/td><th><b>Feature ID&emsp;<\/b><\/th><td>13&emsp;<\/td><\/tr><tr><td>1<\/td><th>ADM2_EN&emsp;<\/th><td>Banan&emsp;<\/td><\/tr><tr><td>2<\/td><th>ADM2_PCODE&emsp;<\/th><td>KH0201&emsp;<\/td><\/tr><tr><td>3<\/td><th>ADM1_EN&emsp;<\/th><td>Battambang&emsp;<\/td><\/tr><tr><td>4<\/td><th>ADM1_PCODE&emsp;<\/th><td>KH02&emsp;<\/td><\/tr><tr><td>5<\/td><th>Male&emsp;<\/th><td>54337&emsp;<\/td><\/tr><tr><td>6<\/td><th>Female&emsp;<\/th><td>53116&emsp;<\/td><\/tr><tr><td>7<\/td><th>T_POP&emsp;<\/th><td>107453&emsp;<\/td><\/tr><tr><td>8<\/td><th>Area.Km2.&emsp;<\/th><td>874.4773&emsp;<\/td><\/tr><tr><td>9<\/td><th>Status&emsp;<\/th><td><4500km2&emsp;<\/td><\/tr><tr><td>10<\/td><th>DENs&emsp;<\/th><td>122.8768&emsp;<\/td><\/tr><tr><td>11<\/td><th>geom&emsp;<\/th><td>sfc_MULTIPOLYGON&emsp;<\/td><\/tr><\/table><\/div>",{"maxWidth":800,"minWidth":50,"autoPan":true,"keepInView":false,"closeButton":true,"closeOnClick":true,"className":""},"13",{"interactive":false,"permanent":false,"direction":"auto","opacity":1,"offset":[0,0],"textsize":"10px","textOnly":false,"className":"","sticky":true},{"stroke":true,"weight":1,"opacity":0.9,"fillOpacity":0.84,"bringToFront":false,"sendToBack":false}]},{"method":"addScaleBar","args":[{"maxWidth":100,"metric":true,"imperial":true,"updateWhenIdle":true,"position":"bottomleft"}]},{"method":"addHomeButton","args":[102.829101562,12.7706909180001,103.221313477,13.1356811520001,true,"banan","Zoom to banan","<strong> banan <\/strong>","bottomright"]},{"method":"addLegend","args":[{"colors":["#6666FF"],"labels":["banan"],"na_color":null,"na_label":"NA","opacity":1,"position":"topright","type":"factor","title":"","extra":null,"layerId":null,"className":"info legend","group":"banan"}]},{"method":"createMapPane","args":["point",440]},{"method":"addCircleMarkers","args":[[12.9967916898305,12.9567883731443,12.8720155591406,13.0282719817933,12.9670658006501,13.059247470427],[103.160327966176,103.145195121288,103.103397307151,103.097624250892,103.051274915643,103.060133124932],6,null,"health_banan",{"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}},"pane":"point","stroke":true,"color":"#333333","weight":1,"opacity":0.9,"fill":true,"fillColor":"#6666FF","fillOpacity":0.6},null,null,["<div class='scrollableContainer'><table class=mapview-popup id='popup'><tr class='coord'><td><\/td><th><b>Feature ID&emsp;<\/b><\/th><td>50&emsp;<\/td><\/tr><tr><td>1<\/td><th>PCODE&emsp;<\/th><td>2&emsp;<\/td><\/tr><tr><td>2<\/td><th>PNAME&emsp;<\/th><td>Battambang&emsp;<\/td><\/tr><tr><td>3<\/td><th>DCODE&emsp;<\/th><td>201&emsp;<\/td><\/tr><tr><td>4<\/td><th>DNAME&emsp;<\/th><td>Banan&emsp;<\/td><\/tr><tr><td>5<\/td><th>CCODE&emsp;<\/th><td>20104&emsp;<\/td><\/tr><tr><td>6<\/td><th>CNAME&emsp;<\/th><td>Chheu Teal&emsp;<\/td><\/tr><tr><td>7<\/td><th>VCODE&emsp;<\/th><td>2010407&emsp;<\/td><\/tr><tr><td>8<\/td><th>VNAME&emsp;<\/th><td>Bay Damram&emsp;<\/td><\/tr><tr><td>9<\/td><th>ODCODE&emsp;<\/th><td>0204&emsp;<\/td><\/tr><tr><td>10<\/td><th>ODNAME&emsp;<\/th><td>Bat Dambang&emsp;<\/td><\/tr><tr><td>11<\/td><th>FACILITCOD&emsp;<\/th><td>020412&emsp;<\/td><\/tr><tr><td>12<\/td><th>FACILITNAM&emsp;<\/th><td>Chheu Teal&emsp;<\/td><\/tr><tr><td>13<\/td><th>COVERNAME&emsp;<\/th><td>Chheu Teal communce, Bat Dambang commune&emsp;<\/td><\/tr><tr><td>14<\/td><th>geom&emsp;<\/th><td>sfc_POINT&emsp;<\/td><\/tr><\/table><\/div>","<div class='scrollableContainer'><table class=mapview-popup id='popup'><tr class='coord'><td><\/td><th><b>Feature ID&emsp;<\/b><\/th><td>51&emsp;<\/td><\/tr><tr><td>1<\/td><th>PCODE&emsp;<\/th><td>2&emsp;<\/td><\/tr><tr><td>2<\/td><th>PNAME&emsp;<\/th><td>Battambang&emsp;<\/td><\/tr><tr><td>3<\/td><th>DCODE&emsp;<\/th><td>201&emsp;<\/td><\/tr><tr><td>4<\/td><th>DNAME&emsp;<\/th><td>Banan&emsp;<\/td><\/tr><tr><td>5<\/td><th>CCODE&emsp;<\/th><td>20104&emsp;<\/td><\/tr><tr><td>6<\/td><th>CNAME&emsp;<\/th><td>Chheu Teal&emsp;<\/td><\/tr><tr><td>7<\/td><th>VCODE&emsp;<\/th><td>2010415&emsp;<\/td><\/tr><tr><td>8<\/td><th>VNAME&emsp;<\/th><td>Anlok Kaong&emsp;<\/td><\/tr><tr><td>9<\/td><th>ODCODE&emsp;<\/th><td>0204&emsp;<\/td><\/tr><tr><td>10<\/td><th>ODNAME&emsp;<\/th><td>Bat Dambang&emsp;<\/td><\/tr><tr><td>11<\/td><th>FACILITCOD&emsp;<\/th><td>020413&emsp;<\/td><\/tr><tr><td>12<\/td><th>FACILITNAM&emsp;<\/th><td>Kantueu II&emsp;<\/td><\/tr><tr><td>13<\/td><th>COVERNAME&emsp;<\/th><td>Kantueu II, Kantueu I, Chheu Teal, Bay Damram Commune&emsp;<\/td><\/tr><tr><td>14<\/td><th>geom&emsp;<\/th><td>sfc_POINT&emsp;<\/td><\/tr><\/table><\/div>","<div class='scrollableContainer'><table class=mapview-popup id='popup'><tr class='coord'><td><\/td><th><b>Feature ID&emsp;<\/b><\/th><td>52&emsp;<\/td><\/tr><tr><td>1<\/td><th>PCODE&emsp;<\/th><td>2&emsp;<\/td><\/tr><tr><td>2<\/td><th>PNAME&emsp;<\/th><td>Battambang&emsp;<\/td><\/tr><tr><td>3<\/td><th>DCODE&emsp;<\/th><td>201&emsp;<\/td><\/tr><tr><td>4<\/td><th>DNAME&emsp;<\/th><td>Banan&emsp;<\/td><\/tr><tr><td>5<\/td><th>CCODE&emsp;<\/th><td>20105&emsp;<\/td><\/tr><tr><td>6<\/td><th>CNAME&emsp;<\/th><td>Chaeng Mean Chey&emsp;<\/td><\/tr><tr><td>7<\/td><th>VCODE&emsp;<\/th><td>2010506&emsp;<\/td><\/tr><tr><td>8<\/td><th>VNAME&emsp;<\/th><td>Changhour Svay&emsp;<\/td><\/tr><tr><td>9<\/td><th>ODCODE&emsp;<\/th><td>0204&emsp;<\/td><\/tr><tr><td>10<\/td><th>ODNAME&emsp;<\/th><td>Bat Dambang&emsp;<\/td><\/tr><tr><td>11<\/td><th>FACILITCOD&emsp;<\/th><td>020405&emsp;<\/td><\/tr><tr><td>12<\/td><th>FACILITNAM&emsp;<\/th><td>Chaeng Mean Chey&emsp;<\/td><\/tr><tr><td>13<\/td><th>COVERNAME&emsp;<\/th><td>Chaeng Mean Chey Commune. 7 Vill&emsp;<\/td><\/tr><tr><td>14<\/td><th>geom&emsp;<\/th><td>sfc_POINT&emsp;<\/td><\/tr><\/table><\/div>","<div class='scrollableContainer'><table class=mapview-popup id='popup'><tr class='coord'><td><\/td><th><b>Feature ID&emsp;<\/b><\/th><td>53&emsp;<\/td><\/tr><tr><td>1<\/td><th>PCODE&emsp;<\/th><td>2&emsp;<\/td><\/tr><tr><td>2<\/td><th>PNAME&emsp;<\/th><td>Battambang&emsp;<\/td><\/tr><tr><td>3<\/td><th>DCODE&emsp;<\/th><td>201&emsp;<\/td><\/tr><tr><td>4<\/td><th>DNAME&emsp;<\/th><td>Banan&emsp;<\/td><\/tr><tr><td>5<\/td><th>CCODE&emsp;<\/th><td>20106&emsp;<\/td><\/tr><tr><td>6<\/td><th>CNAME&emsp;<\/th><td>Phnum Sampov&emsp;<\/td><\/tr><tr><td>7<\/td><th>VCODE&emsp;<\/th><td>2010604&emsp;<\/td><\/tr><tr><td>8<\/td><th>VNAME&emsp;<\/th><td>Phnum Sampov Lech&emsp;<\/td><\/tr><tr><td>9<\/td><th>ODCODE&emsp;<\/th><td>0204&emsp;<\/td><\/tr><tr><td>10<\/td><th>ODNAME&emsp;<\/th><td>Bat Dambang&emsp;<\/td><\/tr><tr><td>11<\/td><th>FACILITCOD&emsp;<\/th><td>020416&emsp;<\/td><\/tr><tr><td>12<\/td><th>FACILITNAM&emsp;<\/th><td>Phnum Sampov&emsp;<\/td><\/tr><tr><td>13<\/td><th>COVERNAME&emsp;<\/th><td>Phnum Sampov Commune, 10 Vill&emsp;<\/td><\/tr><tr><td>14<\/td><th>geom&emsp;<\/th><td>sfc_POINT&emsp;<\/td><\/tr><\/table><\/div>","<div class='scrollableContainer'><table class=mapview-popup id='popup'><tr class='coord'><td><\/td><th><b>Feature ID&emsp;<\/b><\/th><td>54&emsp;<\/td><\/tr><tr><td>1<\/td><th>PCODE&emsp;<\/th><td>2&emsp;<\/td><\/tr><tr><td>2<\/td><th>PNAME&emsp;<\/th><td>Battambang&emsp;<\/td><\/tr><tr><td>3<\/td><th>DCODE&emsp;<\/th><td>201&emsp;<\/td><\/tr><tr><td>4<\/td><th>DNAME&emsp;<\/th><td>Banan&emsp;<\/td><\/tr><tr><td>5<\/td><th>CCODE&emsp;<\/th><td>20107&emsp;<\/td><\/tr><tr><td>6<\/td><th>CNAME&emsp;<\/th><td>Snoeng&emsp;<\/td><\/tr><tr><td>7<\/td><th>VCODE&emsp;<\/th><td>2010704&emsp;<\/td><\/tr><tr><td>8<\/td><th>VNAME&emsp;<\/th><td>Snoeng Kaeut&emsp;<\/td><\/tr><tr><td>9<\/td><th>ODCODE&emsp;<\/th><td>0204&emsp;<\/td><\/tr><tr><td>10<\/td><th>ODNAME&emsp;<\/th><td>Bat Dambang&emsp;<\/td><\/tr><tr><td>11<\/td><th>FACILITCOD&emsp;<\/th><td>020414&emsp;<\/td><\/tr><tr><td>12<\/td><th>FACILITNAM&emsp;<\/th><td>Snoeng&emsp;<\/td><\/tr><tr><td>13<\/td><th>COVERNAME&emsp;<\/th><td>Snoeng Commune, 11 Vill&emsp;<\/td><\/tr><tr><td>14<\/td><th>geom&emsp;<\/th><td>sfc_POINT&emsp;<\/td><\/tr><\/table><\/div>","<div class='scrollableContainer'><table class=mapview-popup id='popup'><tr class='coord'><td><\/td><th><b>Feature ID&emsp;<\/b><\/th><td>55&emsp;<\/td><\/tr><tr><td>1<\/td><th>PCODE&emsp;<\/th><td>2&emsp;<\/td><\/tr><tr><td>2<\/td><th>PNAME&emsp;<\/th><td>Battambang&emsp;<\/td><\/tr><tr><td>3<\/td><th>DCODE&emsp;<\/th><td>201&emsp;<\/td><\/tr><tr><td>4<\/td><th>DNAME&emsp;<\/th><td>Banan&emsp;<\/td><\/tr><tr><td>5<\/td><th>CCODE&emsp;<\/th><td>20108&emsp;<\/td><\/tr><tr><td>6<\/td><th>CNAME&emsp;<\/th><td>Ta Kream&emsp;<\/td><\/tr><tr><td>7<\/td><th>VCODE&emsp;<\/th><td>2010802&emsp;<\/td><\/tr><tr><td>8<\/td><th>VNAME&emsp;<\/th><td>Ta Kream&emsp;<\/td><\/tr><tr><td>9<\/td><th>ODCODE&emsp;<\/th><td>0204&emsp;<\/td><\/tr><tr><td>10<\/td><th>ODNAME&emsp;<\/th><td>Bat Dambang&emsp;<\/td><\/tr><tr><td>11<\/td><th>FACILITCOD&emsp;<\/th><td>020415&emsp;<\/td><\/tr><tr><td>12<\/td><th>FACILITNAM&emsp;<\/th><td>Ta Kream&emsp;<\/td><\/tr><tr><td>13<\/td><th>COVERNAME&emsp;<\/th><td>Ta Kream Commune, 11 Vill&emsp;<\/td><\/tr><tr><td>14<\/td><th>geom&emsp;<\/th><td>sfc_POINT&emsp;<\/td><\/tr><\/table><\/div>"],{"maxWidth":800,"minWidth":50,"autoPan":true,"keepInView":false,"closeButton":true,"closeOnClick":true,"className":""},["50","51","52","53","54","55"],{"interactive":false,"permanent":false,"direction":"auto","opacity":1,"offset":[0,0],"textsize":"10px","textOnly":false,"className":"","sticky":true},null]},{"method":"addHomeButton","args":[103.051274915643,12.8720155591406,103.160327966176,13.059247470427,true,"health_banan","Zoom to health_banan","<strong> health_banan <\/strong>","bottomright"]},{"method":"addLayersControl","args":[["CartoDB.Positron","CartoDB.DarkMatter","OpenStreetMap","Esri.WorldImagery","OpenTopoMap"],["banan","health_banan"],{"collapsed":true,"autoZIndex":true,"position":"topleft"}]},{"method":"addLegend","args":[{"colors":["#6666FF"],"labels":["health_banan"],"na_color":null,"na_label":"NA","opacity":1,"position":"topright","type":"factor","title":"","extra":null,"layerId":null,"className":"info legend","group":"health_banan"}]},{"method":"addHomeButton","args":[102.829101562,12.7706909180001,103.221313477,13.1356811520001,true,null,"Zoom to full extent","<strong>Zoom full<\/strong>","bottomleft"]}],"limits":{"lat":[12.7706909180001,13.1356811520001],"lng":[102.829101562,103.221313477]},"fitBounds":[12.7706909180001,102.829101562,13.1356811520001,103.221313477,[]]},"evals":[],"jsHooks":{"render":[{"code":"function(el, x, data) {\n  return (\n      function(el, x, data) {\n      // get the leaflet map\n      var map = this; //HTMLWidgets.find('#' + el.id);\n      // we need a new div element because we have to handle\n      // the mouseover output separately\n      // debugger;\n      function addElement () {\n      // generate new div Element\n      var newDiv = $(document.createElement('div'));\n      // append at end of leaflet htmlwidget container\n      $(el).append(newDiv);\n      //provide ID and style\n      newDiv.addClass('lnlt');\n      newDiv.css({\n      'position': 'relative',\n      'bottomleft':  '0px',\n      'background-color': 'rgba(255, 255, 255, 0.7)',\n      'box-shadow': '0 0 2px #bbb',\n      'background-clip': 'padding-box',\n      'margin': '0',\n      'padding-left': '5px',\n      'color': '#333',\n      'font': '9px/1.5 \"Helvetica Neue\", Arial, Helvetica, sans-serif',\n      'z-index': '700',\n      });\n      return newDiv;\n      }\n\n\n      // check for already existing lnlt class to not duplicate\n      var lnlt = $(el).find('.lnlt');\n\n      if(!lnlt.length) {\n      lnlt = addElement();\n\n      // grab the special div we generated in the beginning\n      // and put the mousmove output there\n\n      map.on('mousemove', function (e) {\n      if (e.originalEvent.ctrlKey) {\n      if (document.querySelector('.lnlt') === null) lnlt = addElement();\n      lnlt.text(\n                           ' lon: ' + (e.latlng.lng).toFixed(5) +\n                           ' | lat: ' + (e.latlng.lat).toFixed(5) +\n                           ' | zoom: ' + map.getZoom() +\n                           ' | x: ' + L.CRS.EPSG3857.project(e.latlng).x.toFixed(0) +\n                           ' | y: ' + L.CRS.EPSG3857.project(e.latlng).y.toFixed(0) +\n                           ' | epsg: 3857 ' +\n                           ' | proj4: +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs ');\n      } else {\n      if (document.querySelector('.lnlt') === null) lnlt = addElement();\n      lnlt.text(\n                      ' lon: ' + (e.latlng.lng).toFixed(5) +\n                      ' | lat: ' + (e.latlng.lat).toFixed(5) +\n                      ' | zoom: ' + map.getZoom() + ' ');\n      }\n      });\n\n      // remove the lnlt div when mouse leaves map\n      map.on('mouseout', function (e) {\n      var strip = document.querySelector('.lnlt');\n      if( strip !==null) strip.remove();\n      });\n\n      };\n\n      //$(el).keypress(67, function(e) {\n      map.on('preclick', function(e) {\n      if (e.originalEvent.ctrlKey) {\n      if (document.querySelector('.lnlt') === null) lnlt = addElement();\n      lnlt.text(\n                      ' lon: ' + (e.latlng.lng).toFixed(5) +\n                      ' | lat: ' + (e.latlng.lat).toFixed(5) +\n                      ' | zoom: ' + map.getZoom() + ' ');\n      var txt = document.querySelector('.lnlt').textContent;\n      console.log(txt);\n      //txt.innerText.focus();\n      //txt.select();\n      setClipboardText('\"' + txt + '\"');\n      }\n      });\n\n      }\n      ).call(this.getMap(), el, x, data);\n}","data":null},{"code":"function(el, x, data) {\n  return (function(el,x,data){\n           var map = this;\n\n           map.on('keypress', function(e) {\n               console.log(e.originalEvent.code);\n               var key = e.originalEvent.code;\n               if (key === 'KeyE') {\n                   var bb = this.getBounds();\n                   var txt = JSON.stringify(bb);\n                   console.log(txt);\n\n                   setClipboardText('\\'' + txt + '\\'');\n               }\n           })\n        }).call(this.getMap(), el, x, data);\n}","data":null}]}}</script>
</div>
</div>
<div class="callout-note callout callout-style-simple no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<p>Website of <code>mapview</code><br>
<a href="https://r-spatial.github.io/mapview/"><code>mapview</code></a></p>
</div>
</div>
</div>
</section>
</section>
<section id="import-basemaps" class="level3" data-number="2.3.2">
<h3 data-number="2.3.2" class="anchored" data-anchor-id="import-basemaps"><span class="header-section-number">2.3.2</span> Import basemaps</h3>
<p>The package <code>maptiles</code> <span class="citation" data-cites="maptiles">(<a href="references.html#ref-maptiles" role="doc-biblioref">Giraud 2021</a>)</span> allows downlaoding and displaying raster basemaps.<br>
The function <code>get_tiles()</code> allow you to download OSM background maps and the function <code>plot_tiles()</code> allows to display them.<br>
Renders are better if the input data used the same coordinate system as the tiles (<a href="https://github.com/riatelab/maptiles#projection">EPSG:3857</a>).</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(sf)</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(maptiles)</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>district <span class="ot">&lt;-</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"district"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>district <span class="ot">&lt;-</span> <span class="fu">st_transform</span>(district, <span class="dv">3857</span>)</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>osm_tiles <span class="ot">&lt;-</span> <span class="fu">get_tiles</span>(<span class="at">x =</span> district, <span class="at">zoom =</span> <span class="dv">10</span>, <span class="at">crop =</span> <span class="cn">TRUE</span>)</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_tiles</span>(osm_tiles)</span>
<span id="cb8-7"><a href="#cb8-7" 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">"grey20"</span>, <span class="at">lwd =</span> .<span class="dv">7</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a><span class="fu">mtext</span>(<span class="at">side =</span> <span class="dv">1</span>, <span class="at">line =</span> <span class="sc">-</span><span class="dv">2</span>, <span class="at">text =</span> <span class="fu">get_credit</span>(<span class="st">"OpenStreetMap"</span>), <span class="at">col=</span><span class="st">"tomato"</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="02-data_acquisition_files/figure-html/display_point-1.png" class="img-fluid" width="576"></p>
</div>
</div>


<div id="refs" class="references csl-bib-body hanging-indent" role="doc-bibliography" style="display: none">
<div id="ref-JS-Leaflet" class="csl-entry" role="doc-biblioentry">
Agafonkin, Vladimir. 2015. <span>“Leaflet Javascript Libary.”</span>
</div>
<div id="ref-mapview" class="csl-entry" role="doc-biblioentry">
Appelhans, Tim, Florian Detsch, Christoph Reudenbach, and Stefan Woellauer. 2022. <span>“Mapview: Interactive Viewing of Spatial Data in r.”</span> <a href="https://CRAN.R-project.org/package=mapview">https://CRAN.R-project.org/package=mapview</a>.
</div>
<div id="ref-leaflet" class="csl-entry" role="doc-biblioentry">
Cheng, Joe, Bhaskar Karambelkar, and Yihui Xie. 2022. <span>“Leaflet: Create Interactive Web Maps with the JavaScript ’Leaflet’ Library.”</span> <a href="https://CRAN.R-project.org/package=leaflet">https://CRAN.R-project.org/package=leaflet</a>.
</div>
<div id="ref-maptiles" class="csl-entry" role="doc-biblioentry">
Giraud, Timothée. 2021. <span>“Maptiles: Download and Display Map Tiles.”</span> <a href="https://CRAN.R-project.org/package=maptiles">https://CRAN.R-project.org/package=maptiles</a>.
</div>
</div>
</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="./01-introduction.html" class="pagination-link">
        <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Introduction</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>