cmr_cartography-rmd.html 12.5 KB
Newer Older
Facundo Muñoz's avatar
Facundo Muñoz 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
<!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>
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Collection and pre-processing of cartographic information for Cameroon">
<meta property="og:description" content="">
<meta property="og:image" content="/logo.png">
<meta name="twitter:card" content="summary">
<!-- 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>
<body>
    <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>
Facundo Muñoz's avatar
Facundo Muñoz committed
34
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.3.8</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
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
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">
    <span class="fa fa-home fa-lg"></span>
     
  </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>
Facundo Muñoz's avatar
Facundo Muñoz committed
68
<ul class="nav navbar-nav navbar-right"></ul>
Facundo Muñoz's avatar
Facundo Muñoz committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      
      </header><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1>Collection and pre-processing of cartographic information for Cameroon</h1>
                        <h4 class="author">Facundo Muñoz</h4>
            
Facundo Muñoz's avatar
Facundo Muñoz committed
83
            <h4 class="date">2019-04-07</h4>
Facundo Muñoz's avatar
Facundo Muñoz committed
84
      
Facundo Muñoz's avatar
Facundo Muñoz committed
85
86
87
88
89
90
91
92
93
94
95
96
97
      
      <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>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">require</a></span>(raster)
<span class="co">#&gt; Loading required package: raster</span>
<span class="co">#&gt; Loading required package: sp</span>
<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">require</a></span>(rgdal)
<span class="co">#&gt; Loading required package: rgdal</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
98
<span class="co">#&gt; rgdal: version: 1.4-3, (SVN revision 828)</span>
Facundo Muñoz's avatar
Facundo Muñoz committed
99
100
101
102
103
104
105
106
107
108
<span class="co">#&gt;  Geospatial Data Abstraction Library extensions to R successfully loaded</span>
<span class="co">#&gt;  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01</span>
<span class="co">#&gt;  Path to GDAL shared files: /usr/share/gdal/2.1</span>
<span class="co">#&gt;  GDAL binary built with GEOS: TRUE </span>
<span class="co">#&gt;  Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]</span>
<span class="co">#&gt;  Path to PROJ.4 shared files: (autodetected)</span>
<span class="co">#&gt;  Linking to sp version: 1.3-1</span>

<span class="cf">if</span>(<span class="op">!</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">require</a></span>(mapview, <span class="dt">quietly =</span> <span class="ot">TRUE</span>)) 
  <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/cat">cat</a></span>(<span class="st">"We suggest installing the pacakge mapview for interactive visualisation"</span>,
Facundo Muñoz's avatar
Facundo Muñoz committed
109
110
111
      <span class="st">"of cartography from within R"</span>)
<span class="co">#&gt; Warning: replacing previous import 'gdalUtils::gdal_rasterize' by</span>
<span class="co">#&gt; 'sf::gdal_rasterize' when loading 'mapview'</span></code></pre></div>
Facundo Muñoz's avatar
Facundo Muñoz committed
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
<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>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">
cmr_admin3 &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/getData">getData</a></span>(<span class="st">'GADM'</span>, <span class="dt">country =</span> <span class="st">"CMR"</span>, <span class="dt">level=</span><span class="dv">3</span>)
<span class="co"># mapview(cmr_admin3, zcol = "NAME_3")</span></code></pre></div>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">
## This only works locally.
prodel_path &lt;-<span class="st"> "/home/facu/CmisSync/Cirad/Sites/PRODEL/documentLibrary/carto"</span>
water_bodies &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/rgdal/topics/readOGR">readOGR</a></span>(prodel_path, <span class="dt">layer =</span> <span class="st">"wb_cam.shp"</span>)</code></pre></div>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">national_parks &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/rgdal/topics/readOGR">readOGR</a></span>(
  <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/file.path">file.path</a></span>(prodel_path, <span class="st">"WDPA_Mar2018_CMR-shapefile"</span>),
  <span class="st">"WDPA_Mar2018_CMR-shapefile-polygons"</span>
)</code></pre></div>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Not using this for the moment</span>
ps_cam &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/raster">raster</a></span>(<span class="st">"ps_cam.tif"</span>)</code></pre></div>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">animal_density_world &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/raster">raster</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/file.path">file.path</a></span>(prodel_path, <span class="st">"glw"</span>, <span class="st">"WdCt8k_vf_Mn_Rw_To.tif"</span>))
animal_density &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/mask">mask</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/crop">crop</a></span>(animal_density_world, <span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/extent">extent</a></span>(cmr_admin3)), cmr_admin3)

<span class="co"># plot(animal_density)</span>
<span class="co"># summary(animal_density$WdCt8k_vf_Mn_Rw_To)</span></code></pre></div>
</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>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">cmr_dir &lt;-<span class="st"> "./inst/cartography/CMR"</span>
<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/files2">dir.create</a></span>(cmr_dir, <span class="dt">recursive =</span> <span class="ot">TRUE</span>)

<span class="kw"><a href="https://www.rdocumentation.org/packages/rgdal/topics/writeOGR">writeOGR</a></span>(cmr_admin3, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/file.path">file.path</a></span>(cmr_dir, <span class="st">"cmr_admin3.gpkg"</span>), <span class="dt">layer =</span> <span class="st">"cmr_admin3"</span>, <span class="dt">driver =</span> <span class="st">"GPKG"</span>)
<span class="kw"><a href="https://www.rdocumentation.org/packages/rgdal/topics/writeOGR">writeOGR</a></span>(water_bodies, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/file.path">file.path</a></span>(cmr_dir, <span class="st">"water_bodies.gpkg"</span>), <span class="dt">layer =</span> <span class="st">"water_bodies"</span>, <span class="dt">driver =</span> <span class="st">"GPKG"</span>)
<span class="kw"><a href="https://www.rdocumentation.org/packages/rgdal/topics/writeOGR">writeOGR</a></span>(national_parks, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/file.path">file.path</a></span>(cmr_dir, <span class="st">"national_parks.gpkg"</span>), <span class="dt">layer =</span> <span class="st">"national_parks"</span>, <span class="dt">driver =</span> <span class="st">"GPKG"</span>)

<span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/writeRaster">writeRaster</a></span>(animal_density, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/file.path">file.path</a></span>(cmr_dir, <span class="st">"animal.density.tif"</span>))</code></pre></div>
</div>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
        <div id="tocnav">
      <h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
      <ul class="nav nav-pills nav-stacked">
<li><a href="#administrative-borders">Administrative borders</a></li>
      <li><a href="#save-pre-processed-cartography-for-use-within-the-package">Save pre-processed cartography for use within the package</a></li>
      </ul>
</div>
      </div>

</div>


      <footer><div class="copyright">
  <p>Developed by Sylvain Falala, Facundo Muñoz.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
      </footer>
</div>

  

  </body>
</html>