cmr_cartography-rmd.html 13.8 KB
Newer Older
Facundo Muñoz's avatar
Facundo Muñoz committed
1
2
3
4
5
6
7
8
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Collection and pre-processing of cartographic information for Cameroon • mapMCDA</title>
Facundo Muñoz's avatar
Facundo Muñoz committed
9
10
11
12
13
14
15
16
17
18
19
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
Facundo Muñoz's avatar
Facundo Muñoz committed
20
<script src="../pkgdown.js"></script><meta property="og:title" content="Collection and pre-processing of cartographic information for Cameroon">
Facundo Muñoz's avatar
Facundo Muñoz committed
21
<meta property="og:description" content="mapMCDA">
Facundo Muñoz's avatar
Facundo Muñoz committed
22
23
24
25
26
27
<meta property="og:image" content="/logo.png">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
Facundo Muñoz's avatar
Facundo Muñoz committed
28
<body data-spy="scroll" data-target="#toc">
Facundo Muñoz's avatar
Facundo Muñoz committed
29
30
31
32
33
34
35
36
37
38
39
40
    <div class="container template-article">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">mapMCDA</a>
41
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.4.23</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
42
43
44
45
46
47
48
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">
Facundo Muñoz's avatar
Facundo Muñoz committed
49
    <span class="fas fa fas fa-home fa-lg"></span>
Facundo Muñoz's avatar
Facundo Muñoz committed
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
     
  </a>
</li>
<li>
  <a href="../articles/mapMCDA.html">Get started</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Articles
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li>
      <a href="../articles/cmr_cartography-rmd.html">Collection and pre-processing of cartographic information for Cameroon</a>
    </li>
  </ul>
</li>
<li>
  <a href="../news/index.html">Changelog</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right"></ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      
Facundo Muñoz's avatar
Facundo Muñoz committed
84

Facundo Muñoz's avatar
Facundo Muñoz committed
85
86
87
      </header><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
Facundo Muñoz's avatar
Facundo Muñoz committed
88
      <h1 data-toc-skip>Collection and pre-processing of cartographic information for Cameroon</h1>
Facundo Muñoz's avatar
Facundo Muñoz committed
89
90
                        <h4 class="author">Facundo Muñoz</h4>
            
Facundo Muñoz's avatar
Facundo Muñoz committed
91
            <h4 class="date">2020-04-11</h4>
Facundo Muñoz's avatar
Facundo Muñoz committed
92
93
94
95
96
97
98
99
100
      
      
      <div class="hidden name"><code>cmr_cartography-rmd.Rmd</code></div>

    </div>

    
    
<p>Here we demonstrate how we have downloaded and pre-processed the cartographic information for Cameroon which is included in the package.</p>
Facundo Muñoz's avatar
Facundo Muñoz committed
101
<div class="sourceCode" id="cb1"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/library.html">require</a></span>(<span class="no">raster</span>)
Facundo Muñoz's avatar
Facundo Muñoz committed
102
103
<span class="co">#&gt; Loading required package: raster</span>
<span class="co">#&gt; Loading required package: sp</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
104
<span class="fu"><a href="https://rdrr.io/r/base/library.html">require</a></span>(<span class="no">rgdal</span>)
Facundo Muñoz's avatar
Facundo Muñoz committed
105
<span class="co">#&gt; Loading required package: rgdal</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
106
<span class="co">#&gt; rgdal: version: 1.4-8, (SVN revision 845)</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
107
<span class="co">#&gt;  Geospatial Data Abstraction Library extensions to R successfully loaded</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
108
109
<span class="co">#&gt;  Loaded GDAL runtime: GDAL 3.0.2, released 2019/10/28</span>
<span class="co">#&gt;  Path to GDAL shared files: </span>
Facundo Muñoz's avatar
Facundo Muñoz committed
110
<span class="co">#&gt;  GDAL binary built with GEOS: TRUE </span>
Facundo Muñoz's avatar
Facundo Muñoz committed
111
<span class="co">#&gt;  Loaded PROJ.4 runtime: Rel. 6.2.1, November 1st, 2019, [PJ_VERSION: 621]</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
112
<span class="co">#&gt;  Path to PROJ.4 shared files: (autodetected)</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
113
<span class="co">#&gt;  Linking to sp version: 1.4-1</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
114

Facundo Muñoz's avatar
Facundo Muñoz committed
115
116
117
118
119
120
<span class="kw">if</span>(!<span class="fu"><a href="https://rdrr.io/r/base/library.html">require</a></span>(<span class="no">mapview</span>, <span class="kw">quietly</span> <span class="kw">=</span> <span class="fl">TRUE</span>))
  <span class="fu"><a href="https://rdrr.io/r/base/cat.html">cat</a></span>(<span class="st">"We suggest installing the pacakge mapview for interactive visualisation"</span>,
      <span class="st">"of cartography from within R"</span>)
<span class="co">#&gt; Warning in library(package, lib.loc = lib.loc, character.only = TRUE,</span>
<span class="co">#&gt; logical.return = TRUE, : there is no package called 'mapview'</span>
<span class="co">#&gt; We suggest installing the pacakge mapview for interactive visualisation of cartography from within R</span></pre></body></html></div>
Facundo Muñoz's avatar
Facundo Muñoz committed
121
122
123
124
<div id="administrative-borders" class="section level2">
<h2 class="hasAnchor">
<a href="#administrative-borders" class="anchor"></a>Administrative borders</h2>
<p>Download cartography from the Global Administrative Borders Database (GADM, <a href="https://gadm.org/" class="uri">https://gadm.org/</a>) directly from within R.</p>
Facundo Muñoz's avatar
Facundo Muñoz committed
125
126
127
128
129
130
131
132
133
<div class="sourceCode" id="cb2"><html><body><pre class="r">
<span class="no">cmr_admin3</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/raster/man/getData.html">getData</a></span>(<span class="st">'GADM'</span>, <span class="kw">country</span> <span class="kw">=</span> <span class="st">"CMR"</span>, <span class="kw">level</span><span class="kw">=</span><span class="fl">3</span>)
<span class="co"># mapview(cmr_admin3, zcol = "NAME_3")</span></pre></body></html></div>
<div class="sourceCode" id="cb3"><html><body><pre class="r">
<span class="co">## This only works locally.</span>
<span class="no">prodel_path</span> <span class="kw">&lt;-</span> <span class="st">"/home/facu/CmisSync/Cirad/Sites/PRODEL/documentLibrary/carto"</span>
<span class="no">water_bodies</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/rgdal/man/readOGR.html">readOGR</a></span>(<span class="no">prodel_path</span>, <span class="kw">layer</span> <span class="kw">=</span> <span class="st">"wb_cam.shp"</span>)</pre></body></html></div>
<div class="sourceCode" id="cb4"><html><body><pre class="r"><span class="no">national_parks</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/rgdal/man/readOGR.html">readOGR</a></span>(
  <span class="fu"><a href="https://rdrr.io/r/base/file.path.html">file.path</a></span>(<span class="no">prodel_path</span>, <span class="st">"WDPA_Mar2018_CMR-shapefile"</span>),
Facundo Muñoz's avatar
Facundo Muñoz committed
134
  <span class="st">"WDPA_Mar2018_CMR-shapefile-polygons"</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
135
136
137
138
139
)</pre></body></html></div>
<div class="sourceCode" id="cb5"><html><body><pre class="r"><span class="co"># Not using this for the moment</span>
<span class="no">ps_cam</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/raster/man/raster.html">raster</a></span>(<span class="st">"ps_cam.tif"</span>)</pre></body></html></div>
<div class="sourceCode" id="cb6"><html><body><pre class="r"><span class="no">animal_density_world</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/raster/man/raster.html">raster</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/file.path.html">file.path</a></span>(<span class="no">prodel_path</span>, <span class="st">"glw"</span>, <span class="st">"WdCt8k_vf_Mn_Rw_To.tif"</span>))
<span class="no">animal_density</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/raster/man/mask.html">mask</a></span>(<span class="fu"><a href="https://rdrr.io/pkg/raster/man/crop.html">crop</a></span>(<span class="no">animal_density_world</span>, <span class="fu"><a href="https://rdrr.io/pkg/raster/man/extent.html">extent</a></span>(<span class="no">cmr_admin3</span>)), <span class="no">cmr_admin3</span>)
Facundo Muñoz's avatar
Facundo Muñoz committed
140
141

<span class="co"># plot(animal_density)</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
142
<span class="co"># summary(animal_density$WdCt8k_vf_Mn_Rw_To)</span></pre></body></html></div>
Facundo Muñoz's avatar
Facundo Muñoz committed
143
144
145
146
147
</div>
<div id="save-pre-processed-cartography-for-use-within-the-package" class="section level2">
<h2 class="hasAnchor">
<a href="#save-pre-processed-cartography-for-use-within-the-package" class="anchor"></a>Save pre-processed cartography for use within the package</h2>
<p>Prefer standard and modern Open Geospatial Consortium (<a href="http://www.opengeospatial.org/">OGC</a>) formats: GeoPackage for vector maps and GeoTiff for raster images.</p>
Facundo Muñoz's avatar
Facundo Muñoz committed
148
149
<div class="sourceCode" id="cb7"><html><body><pre class="r"><span class="no">cmr_dir</span> <span class="kw">&lt;-</span> <span class="st">"./inst/cartography/CMR"</span>
<span class="fu"><a href="https://rdrr.io/r/base/files2.html">dir.create</a></span>(<span class="no">cmr_dir</span>, <span class="kw">recursive</span> <span class="kw">=</span> <span class="fl">TRUE</span>)
Facundo Muñoz's avatar
Facundo Muñoz committed
150

Facundo Muñoz's avatar
Facundo Muñoz committed
151
152
153
<span class="fu"><a href="https://rdrr.io/pkg/rgdal/man/writeOGR.html">writeOGR</a></span>(<span class="no">cmr_admin3</span>, <span class="fu"><a href="https://rdrr.io/r/base/file.path.html">file.path</a></span>(<span class="no">cmr_dir</span>, <span class="st">"cmr_admin3.gpkg"</span>), <span class="kw">layer</span> <span class="kw">=</span> <span class="st">"cmr_admin3"</span>, <span class="kw">driver</span> <span class="kw">=</span> <span class="st">"GPKG"</span>)
<span class="fu"><a href="https://rdrr.io/pkg/rgdal/man/writeOGR.html">writeOGR</a></span>(<span class="no">water_bodies</span>, <span class="fu"><a href="https://rdrr.io/r/base/file.path.html">file.path</a></span>(<span class="no">cmr_dir</span>, <span class="st">"water_bodies.gpkg"</span>), <span class="kw">layer</span> <span class="kw">=</span> <span class="st">"water_bodies"</span>, <span class="kw">driver</span> <span class="kw">=</span> <span class="st">"GPKG"</span>)
<span class="fu"><a href="https://rdrr.io/pkg/rgdal/man/writeOGR.html">writeOGR</a></span>(<span class="no">national_parks</span>, <span class="fu"><a href="https://rdrr.io/r/base/file.path.html">file.path</a></span>(<span class="no">cmr_dir</span>, <span class="st">"national_parks.gpkg"</span>), <span class="kw">layer</span> <span class="kw">=</span> <span class="st">"national_parks"</span>, <span class="kw">driver</span> <span class="kw">=</span> <span class="st">"GPKG"</span>)
Facundo Muñoz's avatar
Facundo Muñoz committed
154

Facundo Muñoz's avatar
Facundo Muñoz committed
155
<span class="fu"><a href="https://rdrr.io/pkg/raster/man/writeRaster.html">writeRaster</a></span>(<span class="no">animal_density</span>, <span class="fu"><a href="https://rdrr.io/r/base/file.path.html">file.path</a></span>(<span class="no">cmr_dir</span>, <span class="st">"animal.density.tif"</span>))</pre></body></html></div>
Facundo Muñoz's avatar
Facundo Muñoz committed
156
157
158
</div>
  </div>

Facundo Muñoz's avatar
Facundo Muñoz committed
159
160
161
162
  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">

        <nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
    </nav>
Facundo Muñoz's avatar
Facundo Muñoz committed
163
164
165
166
167
</div>

</div>


Facundo Muñoz's avatar
Facundo Muñoz committed
168

Facundo Muñoz's avatar
Facundo Muñoz committed
169
170
171
172
173
      <footer><div class="copyright">
  <p>Developed by Sylvain Falala, Facundo Muñoz.</p>
</div>

<div class="pkgdown">
Facundo Muñoz's avatar
Facundo Muñoz committed
174
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.</p>
Facundo Muñoz's avatar
Facundo Muñoz committed
175
</div>
Facundo Muñoz's avatar
Facundo Muñoz committed
176

Facundo Muñoz's avatar
Facundo Muñoz committed
177
178
179
180
181
      </footer>
</div>

  

Facundo Muñoz's avatar
Facundo Muñoz committed
182

Facundo Muñoz's avatar
Facundo Muñoz committed
183
184
  </body>
</html>