-
Notifications
You must be signed in to change notification settings - Fork 9
/
GIS with QGIS.html
1108 lines (990 loc) · 63.3 KB
/
GIS with QGIS.html
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns# fb: https://www.facebook.com/2008/fbml">
<head>
<title>GIS with QGIS - Economic Growth and Comparative Development</title>
<!-- Using the latest rendering mode for IE -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://econgrowth.github.io/images/favicomatic/favicon.ico" rel="icon">
<link rel="canonical" href="https://econgrowth.github.io/GIS with QGIS.html">
<meta name="author" content="Ömer Özak" />
<meta name="keywords" content="Economic Growth,Macroeconomics,IPython,Notebooks" />
<meta name="description" content="Using Geographic Information Systems (GIS) in and ¶ Geographic Information Systems (GIS)¶ GIS refers to methods of storing, displaying and analyzing geogaphical information. These methods have become essential in economic analysis (as you have noticed from the reading list for our Ph.D. course on economic growth). For this reason, it is good that you acquaint yourself with these methods. They will prove very useful when doing research, especially to show the spatial distribution of your variables of interest, contructing new measures, or doing spatial analysis." />
<meta property="og:site_name" content="Economic Growth and Comparative Development" />
<meta property="og:type" content="article"/>
<meta property="og:title" content="GIS with QGIS"/>
<meta property="og:url" content="https://econgrowth.github.io/GIS with QGIS.html"/>
<meta property="og:description" content="Using Geographic Information Systems (GIS) in and ¶ Geographic Information Systems (GIS)¶ GIS refers to methods of storing, displaying and analyzing geogaphical information. These methods have become essential in economic analysis (as you have noticed from the reading list for our Ph.D. course on economic growth). For this reason, it is good that you acquaint yourself with these methods. They will prove very useful when doing research, especially to show the spatial distribution of your variables of interest, contructing new measures, or doing spatial analysis."/>
<meta property="article:published_time" content="2016-12-29" />
<meta property="article:section" content="Ph.D." />
<meta property="article:tag" content="Economic Growth" />
<meta property="article:tag" content="Macroeconomics" />
<meta property="article:tag" content="IPython" />
<meta property="article:tag" content="Notebooks" />
<meta property="article:author" content="Ömer Özak" />
<!-- Bootstrap -->
<link rel="stylesheet" href="https://econgrowth.github.io/theme/css/bootstrap.spacelab.min.css" type="text/css"/>
<link href="https://econgrowth.github.io/theme/css/font-awesome.min.css" rel="stylesheet">
<link href="https://econgrowth.github.io/theme/css/pygments/default.css" rel="stylesheet">
<link rel="stylesheet" href="https://econgrowth.github.io/theme/css/style.css" type="text/css"/>
<link href="https://econgrowth.github.io/static/custom.css" rel="stylesheet">
<link href="https://econgrowth.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate"
title="Economic Growth and Comparative Development ATOM Feed"/>
<link href="https://econgrowth.github.io/feeds/phd.atom.xml" type="application/atom+xml" rel="alternate"
title="Economic Growth and Comparative Development Ph.D. ATOM Feed"/>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="https://econgrowth.github.io/" class="navbar-brand">
Economic Growth and Comparative Development </a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li><a href="/pages/Syllabus.html">Syllabus</a></li>
<li><a href="/pages/Reading List.html">Reading List</a></li>
<li><a href="/pages/Lecture Notes.html">Lecture Notes</a></li>
<li><a href="/pages/Computation.html">Computation</a></li>
<li><a href="/pages/Useful Tips.html">Useful Tips</a></li>
<li><a href="/pages/CV.html">CV</a></li>
<li><a href="/pages/Contact.html">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
</div> <!-- /.navbar -->
<!-- Banner -->
<!-- End Banner -->
<div class="container">
<div class="row">
<div class="col-sm-9">
<section id="content">
<article>
<header class="page-header">
<h1>
<a href="https://econgrowth.github.io/GIS with QGIS.html"
rel="bookmark"
title="Permalink to GIS with QGIS">
GIS with QGIS
</a>
</h1>
</header>
<div class="entry-content">
<div class="panel">
<div class="panel-body">
<footer class="post-info">
<span class="label label-default">Date</span>
<span class="published">
<i class="fa fa-calendar"></i><time datetime="2016-12-29T10:20:00-06:00"> Thu 29 December 2016</time>
</span>
<span class="label label-default">Tags</span>
<a href="https://econgrowth.github.io/tag/economic-growth.html">Economic Growth</a>
/
<a href="https://econgrowth.github.io/tag/macroeconomics.html">Macroeconomics</a>
/
<a href="https://econgrowth.github.io/tag/ipython.html">IPython</a>
/
<a href="https://econgrowth.github.io/tag/notebooks.html">Notebooks</a>
</footer><!-- /.post-info --> </div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Using-Geographic-Information-Systems-(GIS)-in--and-">Using Geographic Information Systems (GIS) in <a href="http://www.qgis.org/"><img src="../images/pics/QGis_Logo.png" alt="QGIS" style="width: 60px;" /></a><a href="http://www.qgis.org/" /> and <a href="http://www.python.org/"><img src="../images/pics/python-logo.png" alt="Python" /></a><a class="anchor-link" href="#Using-Geographic-Information-Systems-(GIS)-in--and-">¶</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Geographic-Information-Systems-(GIS)">Geographic Information Systems (GIS)<a class="anchor-link" href="#Geographic-Information-Systems-(GIS)">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>GIS refers to methods of storing, displaying and analyzing geogaphical information. These methods have become essential in economic analysis (as you have noticed from the reading list for our Ph.D. course on economic growth). For this reason, it is good that you acquaint yourself with these methods. They will prove very useful when doing research, especially to show the spatial distribution of your variables of interest, contructing new measures, or doing spatial analysis.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Software">Software<a class="anchor-link" href="#Software">¶</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Commercial">Commercial<a class="anchor-link" href="#Commercial">¶</a></h2><p>There are various GIS specialized programs and packages. <a href="www.esri.com">ESRI</a> produces ArcGIS, which is the most known and commonly used commercial software. It is very easy to use to produce maps and do simple computations. Most universities (including ours) offer it in their computer labs. The main disadvantages are that it requires a computer running Windows, it is costly, and extremely slow for computations. Of course this is changing, e.g., now you can use it online.</p>
<p>Nonetheless, I always suggest you use and learn open-source alternatives.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Open-Source">Open Source<a class="anchor-link" href="#Open-Source">¶</a></h2><p>There are many open source GIS projects, many of which are supported/gathered at <a href="http://www.osgeo.org/"><img src="../images/pics/OSGEO-logo.png" alt="GRASS" style="width: 80px;" /></a>. The most known and widely used seem to be <a href="http://grass.osgeo.org/"><img src="../images/pics/Grass-logo.png" alt="GRASS" style="width: 100px;" /></a> and <a href="http://www.qgis.org/"><img src="../images/pics/QGis_Logo.png" alt="QGIS" style="width: 50px;" /></a>, although Python is increasingly becoming the language of GIS. QGIS can be programmed in Python and many web-based GIS services and databases are programmed in Python. Furthermore, there are many new Python packages which allow you to import, export, analyze, visualize, etc. GIS data. THis notebook will serve as a basic introduction, which I hope to develop further with time. Many of the solutions provded here have been implemented by myself or taken from sources on the web (regretfully I did not keep track from where I took some ideas or snipplets of code, so I cannot provide due credit).</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Installation">Installation<a class="anchor-link" href="#Installation">¶</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="QGIS">QGIS<a class="anchor-link" href="#QGIS">¶</a></h1><p>Install <a href="https://www.qgis.org">QGIS</a> using their installers. On OSX you may need to follow the instructions below.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Anaconda-(Suggested)">Anaconda (Suggested)<a class="anchor-link" href="#Anaconda-(Suggested)">¶</a></h1><p>If you followed the steps for installing the Continuum Anaconda Python Distribution and for creating the <code>GeoPythonXenv</code> (<a href="https://econgrowth.github.io/pages/Computation.html">presented here</a>), then you are basically set for working with GIS in Python + R.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Non-Anaconda-installation-(Discouraged---old-and-may-not-work-anymore)">Non Anaconda installation (Discouraged - old and may not work anymore)<a class="anchor-link" href="#Non-Anaconda-installation-(Discouraged---old-and-may-not-work-anymore)">¶</a></h1><p>Here I will give you the basic idea of what you need to install to have a working GIS environment. I assume you have already installed <a href="https://www.enthought.com/products/canopy/academic/">Canopy</a> with all the pakages provided by Enthought. Additionally, you will need to install <a href="http://grass.osgeo.org">GRASS</a>, <a href="https://www.qgis.org">QGIS</a>, and <a href="http://www.gdal.org/">GDAL/OGR</a>.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Windows">Windows<a class="anchor-link" href="#Windows">¶</a></h3><p>Download the installers in each of these websites and you should be done!</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Mac-OSX">Mac OSX<a class="anchor-link" href="#Mac-OSX">¶</a></h3><p>There are various methods of getting these on your computer.</p>
<ol>
<li>Try the installers on each website</li>
<li>Use the installers provided by <a href="http://www.kyngchaos.com/">Kyngchaos</a></li>
<li>Use <a href="http://brew.sh/">HomeBrew</a></li>
</ol>
<p>I used to install using the installers provided by <a href="http://www.kyngchaos.com/">Kyngchaos</a>. But I have moved to using <a href="http://brew.sh/">HomeBrew</a>, which allows you install many other GNU projects. To do so, open a terminal window (I recommend getting <a href="http://www.iterm2.com/">iTerm2</a>, which is more powerful than the one provided by OSX) and run the following code (I think you will need to have Xcode and its command-line utilities installed)</p>
<pre><code>ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew doctor
</code></pre>
<p>This should install HomeBrew on your system and let you know of any issues. Once you have done so and have a working homebrew installation, you will be able to install packages and programs using the <code>brew install</code> command. Before doing so, you should run the following commands</p>
<pre><code>brew update
brew tap homebrew/science
</code></pre>
<p>This will update HomeBrew's formulas to the latest version. Now issue the command</p>
<pre><code> brew cask install qgis
</code></pre>
<p>You should be done and have teh latest vanilla version of <code>QGIS</code> in your Applications folder.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Not-a-vanilla-fan?">Not a vanilla fan?<a class="anchor-link" href="#Not-a-vanilla-fan?">¶</a></h3><p>Ok. sometimes you want <code>QGIS</code> with all the additional blows and whistles, e.g. integration with <code>GRASS</code>, etc. In that case, you need a bit more work. Luckily there are awesome people who are trying to keep this streamlined and working for all of us. Head to <a href="https://github.com/OSGeo/homebrew-osgeo4mac">osgeo4mac</a> and follow their instructions.</p>
<h3 id="Note-on-GDAL-+-Canopy">Note on GDAL + Canopy<a class="anchor-link" href="#Note-on-GDAL-+-Canopy">¶</a></h3><p>It seems Canopy already has GDAL incorporated, at least so it seems on Mac OS X. But there is a bug that might prevent it from working, unless you add the following line on your <code>.profile</code></p>
<pre><code> export GDAL_DATA=~/Library/Enthought/Canopy_64bit/User/share/gdal</code></pre>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Data">Data<a class="anchor-link" href="#Data">¶</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Ok...now that we have a working GIS desktop system, let us talk a little about types of data. All GIS data includes elements with their properties and their geographical information like location, as determined by e.g. latitude and longitude, address, zip code, etc. So, for example an element might be a country, its properties might be GDP per capita, Gini coefficient, etc. and its location. Another example might be a restaurant with its menu and prices, services (dine-in, take-out, delivery), area of service and location.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Formats">Formats<a class="anchor-link" href="#Formats">¶</a></h2><p>GIS comes in very different formats, althogh most of them can be categorizewd into two types <strong>Rasters</strong> and <strong>Vector</strong> formats.</p>
<ol>
<li><strong>Rasters</strong> are basically matrices $R=[R_{ij}]$ of size $m\times n$ that hold numerical information, where each cell $R_{ij}$ shows the value of interest at a specific location $ij$. Where this location $ij$ is, is determined by the actual format and the projection of the data (this will be clearer below). </li>
<li><strong>Vectors</strong> represent a geographical element geometrically and include additional information on it. An element can be represented as one of the following geometries:<ol>
<li>A point or set of unconnected points</li>
<li>A line or set of (un)connected lines</li>
<li>A Polygon</li>
<li>A set of one or various of the previous types</li>
</ol>
</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Examples-of-Raster-formats:">Examples of Raster formats:<a class="anchor-link" href="#Examples-of-Raster-formats:">¶</a></h2><ol>
<li><strong>GeoTiff</strong>: Multipurpose raster format.</li>
<li><strong>ESRI Grid</strong>: Main ESRI raster format.</li>
<li><strong>Digital Elevation Model (DEM)</strong>: Used by the US Geological Survey to record elevation data.</li>
<li><strong>Band Interleaved by Line, Band Interleaved by Pixel, Band Sequential (BIL, BIP, BSQ)</strong>: These data formats are typically used by remote sensing systems.</li>
<li><strong>Digital Raster Graphic (DRG)</strong>: This format is used to store digital scans of paper maps.</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Examples-of-Vector-formats:">Examples of Vector formats:<a class="anchor-link" href="#Examples-of-Vector-formats:">¶</a></h2><ol>
<li><strong>Shapefile</strong>: An open specification, developed by ESRI, for storing and exchanging GIS data. A Shapefile actually consists of a collection of files all with the same base name, for example hawaii.shp, hawaii.shx, hawaii.dbf, and so on. </li>
<li><strong>Simple Features</strong>: An OpenGIS standard for storing geographical data (points, lines, polygons) along with associated attributes.</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li><strong>TIGER/Line</strong>: A text-based format previously used by the U.S. Census Bureau to describe geographic features such as roads, buildings, rivers, and coastlines. More recent data comes in the Shapefile format, so the TIGER/Line format is only used for earlier Census Bureau datasets.</li>
<li><strong>Coverage</strong>: Proprietary data format used by ESRI's ARC/INFO system.</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Other-formats:">Other formats:<a class="anchor-link" href="#Other-formats:">¶</a></h2><ol>
<li><strong>Well-known Text (WKT)</strong>: text-based format for representing a single geographic feature such as a polygon or line.</li>
<li><strong>Well-known Binary (WKB)</strong>: similar to WKT uses binary data rather than text to represent a single geographic feature.</li>
<li><strong>GeoJSON</strong>: An open format for encoding geographic data structures, based on the JSON data interchange format. This is becoming the internet's prefered format.</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Sources-of-Data">Sources of Data<a class="anchor-link" href="#Sources-of-Data">¶</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>There are many places to find data. Some useful links to start are:</p>
<ul>
<li><a href="http://worldmap.harvard.edu/">WorldMap</a></li>
<li><a href="http://www.fao.org/geonetwork">FAO's GeoNetwork</a></li>
<li><a href="https://usa.ipums.org/usa/volii/boundaries.shtml">IPUMS USA Boundary files for Censuses</a></li>
<li><a href="https://international.ipums.org/international/gis.shtml">IPUMS International Boundary files for Censuses</a></li>
<li><a href="http://www.gadm.org/">GADM database of Global Administrative Areas</a></li>
<li><a href="http://www.fao.org/geonetwork/srv/en/metadata.show?id=12691">Global Administrative Unit Layers</a></li>
<li><a href="http://www.naturalearthdata.com/">Natural Earth</a>: Various vector and raster files with all kinds of geographical, cultural and socioeconomic variables</li>
</ul>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ul>
<li><a href="http://www.iscgm.org/cgi-bin/fswiki/wiki.cgi?page=Summary">Global Map</a></li>
<li><a href="http://worldmap.harvard.edu/data/geonode:Digital_Chart_of_the_World">Digital Chart of the World</a></li>
<li><a href="http://www.sage.wisc.edu/mapsdatamodels.html">Sage</a> and <a href="http://www.sage.wisc.edu/atlas/maps.php">Sage Atlas</a></li>
<li><a href="http://www.geog.mcgill.ca/~nramankutty/Datasets/Datasets.html">Ramankutti's Datasets on land use, crops, etc.</a></li>
<li><a href="http://sedac.ciesin.columbia.edu/data/sets/browse">SEDAC at Columbia University</a>: Gridded Population, Hazzards, etc.</li>
<li><a href="http://msi.nga.mil/NGAPortal/MSI.portal?_nfpb=true&_pageLabel=msi_portal_page_62&pubCode=0015">World Port Index</a></li>
<li><a href="http://eros.usgs.gov/elevation-products">USGS elevation maps</a></li>
</ul>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ul>
<li><a href="https://ozak.github.io/Caloric-Suitability-Index/">Caloric Suitability Index CSI</a>: Agricultural suitability data</li>
<li><a href="https://www.prio.org/Data/">Peace Research Institute Oslo (PRIO) Conflict Data</a></li>
<li><a href="https://acleddata.com/curated-data-files/">The Armed Conflict Location & Event Data Project (ACLED)</a></li>
<li><a href="https://www.start.umd.edu/gtd/">Global Terrorism Database (START-GTD)</a></li>
</ul>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ul>
<li><a href="http://www.ngdc.noaa.gov/mgg/topo/globe.html">NOOA's Global Land One-km Base Elevation Project (GLOBE)</a></li>
<li><a href="http://ngdc.noaa.gov/eog/download.html">NOOA Nightlight data</a>: This is the data used by Henderson, Storeygard, and Weil AER 2012 paper.</li>
<li><a href="http://www.ngdc.noaa.gov/ngdcinfo/onlineaccess.html">Other NOOA Data</a></li>
<li><a href="http://gecon.yale.edu/">GEcon</a></li>
<li><a href="http://openstreetmap.org">OpenStreetMap</a></li>
<li><a href="http://www.census.gov/geo/maps-data/data/tiger.html">U.S. Census TIGER</a></li>
<li><a href="http://www.icr.ethz.ch/data/other/greg">Geo-referencing of Ethnic Groups</a></li>
</ul>
<p>See also <a href="http://en.wikipedia.org/wiki/List_of_GIS_data_sources">Wikipedia links</a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Creating-maps-and-exploring-data">Creating maps and exploring data<a class="anchor-link" href="#Creating-maps-and-exploring-data">¶</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Let us start by creating some simple maps. For this, create a directory called <code>mydata</code> in your <code>$HOME</code> directory and download the following datasets and extract them:</p>
<ol>
<li>The full <a href="https://gadm.org/">GADM</a> shape file is available for download <a href="https://biogeo.ucdavis.edu/data/gadm3.6/gadm36_shp.zip">here</a>, since it is large, also download the file for your country of origin from <a href="https://gadm.org/download_country_v3.html">here</a>.</li>
<li><a href="http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip">Natural Earth's Populated Places dataset</a> </li>
<li><a href="https://nelson.wisc.edu/sage/data-and-models/atlas/data.php?incdataset=Suitability%20for%20Agriculture">Ramankutty's Suitability Index</a></li>
<li><a href="http://ngdc.noaa.gov/eog/data/web_data/v4composites/F182012.v4.tar">Lights Data for 2012</a></li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now, open QGIS. You should see something like this</p>
<p><a href="../images/pics/GIS/QGIS-main.png"><img src="../images/pics/GIS/QGIS-main.png" alt="QGIS open" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>To open a file in QGIS you can:</p>
<ul>
<li>Use <code>Finder</code> or <code>Windows Explorer</code> to navigate to the file and <code>double-click</code> on it.</li>
<li>Use the <code>Layer</code> menu in QGIS</li>
</ul>
<p><a href="../images/pics/GIS/QGIS-Layer-menu.png"><img src="../images/pics/GIS/QGIS-Layer-menu.png" alt="QGIS Layer Menu" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ul>
<li>Use the toolbar on the left</li>
</ul>
<p><a href="./images./pics/GIS/QGIS-file-toolbar.png"><img src="../images/pics/GIS/QGIS-file-toolbar.png" alt="QGIS File Toolbar" style="width: 20px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Working-with-vector-layers">Working with vector layers<a class="anchor-link" href="#Working-with-vector-layers">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Let's start by adding the vector file for your country of origin using the <code>add vector layer</code> button in the toolbar.</p>
<p><a href="../images/pics/GIS/QGIS-add-vector-layer.png"><img src="../images/pics/GIS/QGIS-add-vector-layer.png" alt="QGIS add vector layer" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>I have added the full GADM dataset, so it looks like this</p>
<p><a href="../images/pics/GIS/QGIS-GADM.png"><img src="../images/pics/GIS/QGIS-GADM.png" alt="GADM layer in QGIS" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now we can use various tools available within QGIS to learn about the data, select the data, analyze the data, etc.</p>
<ol>
<li><p>The handtool for panning: <a href="../images/pics/GIS/QGIS-handtool.png"><img src="../images/pics/GIS/QGIS-handtool.png" alt="QGIS-handtool" /></a></p>
<ul>
<li>Try it out, use the tool to move your country around the screen.</li>
</ul>
</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li><p>Zoom in/out/to selection/full: <a href="../images/pics/GIS/QGIS-zoom-toolbar.png"><img src="../images/pics/GIS/QGIS-zoom-toolbar.png" alt="QGIS-Zoom" /></a></p>
<ul>
<li>Try it out, by zooming around your city of birth.</li>
</ul>
</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li><p>Identify Features: <a href="../images/pics/GIS/QGIS-identify-features.png"><img src="../images/pics/GIS/QGIS-identify-features.png" alt="QGIS-identify-features" /></a></p>
<ul>
<li>Try it out, click on the feature you just zoomed into. Did you zoom into the correct feature?</li>
</ul>
</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li><p>Select Features: <a href="../images/pics/GIS/QGIS-select-features.png"><img src="../images/pics/GIS/QGIS-select-features.png" alt="QGIS-select-features" /></a></p>
<ul>
<li>Try it out, select the feature of the region where you were born.</li>
</ul>
</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Besides the geometrical information that we observe, most Shape files have other information relating to each feature. This information is contained in the <em>Attribute Table</em>, which can be accessed with</p>
<ul>
<li>the <code>Open Attribute Table</code> button <a href="../images/pics/GIS/QGIS-attribute-table.png"><img src="../images/pics/GIS/QGIS-attribute-table.png" alt="QGIS-attribute-table" /></a></li>
</ul>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ul>
<li>By <code>right-clicking</code> on the name of the layer in the left panel</li>
</ul>
<p><a href="../images/pics/GIS/QGIS-attribute-table2.png"><img src="../images/pics/GIS/QGIS-attribute-table2.png" alt="QGIS-attribute-table2" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Doing so shows you the additional information contained in the shape file. For the GADM file it includes</p>
<ul>
<li>the identification number of the feature <code>OBJECTID</code></li>
<li>the identification number of the country (Administrative Level 0) to which the feature belongs <code>ID_0</code></li>
<li>the ISO-3 code of the country to which the feature belongs <code>ISO</code></li>
<li>the name of the country to which the feature belongs <code>NAME_0</code></li>
<li>the identification number of the region in the country (Administrative Level 1) to which the feature belongs <code>ID_1</code></li>
</ul>
<p>etc.</p>
<p><a href="../images/pics/GIS/QGIS-attribute-table3.png"><img src="../images/pics/GIS/QGIS-attribute-table3.png" alt="QGIS-attribute-table3" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can use this information to color our maps, or to select features for further analysis. I will use the <code>select feature using an expression</code> button <img src="../images/pics/GIS/QGIS-select-feature-attributes-button.png" alt="QGIS-select-feature-attributes-button"> to select all features which have the ISO-3 code for Kenya. Once you click on the <img src="../images/pics/GIS/QGIS-select-feature-attributes-button.png" alt="QGIS-select-feature-attributes-button"> button, you will see the following window, where you can write the expression to be used to select features. In this case I wrote the expression</p>
<pre><code>'ISO'='KEN'
</code></pre>
<p>to select all features with Kenya's ISO-3 code.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><a href="../images/pics/GIS/QGIS-select-features-by-ISO.png"><img src="../images/pics/GIS/QGIS-select-features-by-ISO.png" alt="QGIS-select-features-by-ISO" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Sometimes we will want to work with a subset of features, especially if the data we are working has many features, like the GADM data. To select a subset of the features and only work with those, use the <code>Layer->Query</code> option in the <code>Menu</code> as shown below</p>
<p><a href="../images/pics/GIS/QGIS-Query.png"><img src="../images/pics/GIS/QGIS-Query.png" alt="QGIS-Query" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This opens a window where you can write expression as the previous one, to select features by their attributes. These are <code>SQL</code> expressions and have to conform to <code>SQL</code>'s grammar (we will not go into this at this point). Once I execute the same expression as above</p>
<pre><code>'ISO'='KEN'
</code></pre>
<p>QGIS leaves only the features in Kenya for analysis.</p>
<p><a href="../images/pics/GIS/QGIS-Query-KEN.png"><img src="../images/pics/GIS/QGIS-Query-KEN.png" alt="QGIS-Query-KEN" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Let us zoom into these features by <code>right-clicking</code> on the name of the layer and choosing <code>Zoom to Layer Extent</code>. This shows the extent of Kenya alone.</p>
<p><a href="../images/pics/GIS/QGIS-zoomed-KEN.png"><img src="../images/pics/GIS/QGIS-zoomed-KEN.png" alt="QGIS-zoomed-KEN" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Other important tools can be found in <code>Layer -> Properties</code> or by <code>double-clicking</code> on the layer's name</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Exercise">Exercise<a class="anchor-link" href="#Exercise">¶</a></h3><ol>
<li>Load the complete GADM dataset.</li>
<li>Select the regions of your country of origin, so that you will work only on these.</li>
<li>Save the result to a new layer/shapefile called <code>your_country.shp</code></li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Vector-Menu">Vector Menu<a class="anchor-link" href="#Vector-Menu">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The <code>Vector</code> menu has many tools that can be applied to vector layers. Let's use some of these to create new layers.</p>
<p>Using the <code>Vector -> Geometry Tools -> Singlepart to Mutliparts</code> we can generate a new layer and shape file where features are aggregated according to some characteristic. Let us use this tool to aggregate administrative level 2 features to the administrative level 0 (Country) level. Thus, each feature will be a country (administrative level 0) instead of the current administrative level 2.</p>
<p><a href="../images/pics/GIS/QGIS-SinglePart-MultiPart.png"><img src="../images/pics/GIS/QGIS-SinglePart-MultiPart.png" alt="QGIS-SinglePart-MultiPart" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Using the <code>Vector -> Geometry Tools -> Mutliparts to singlepart</code> we can generate a new layer and shape file where features are disaggregated.</p>
<p><a href="../images/pics/GIS/QGIS-MultiPart-SinglePart.png"><img src="../images/pics/GIS/QGIS-MultiPart-SinglePart.png" alt="QGIS-MultiPart-SinglePart" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Exercises">Exercises<a class="anchor-link" href="#Exercises">¶</a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li>Load the Populated Places data.</li>
<li>Select the cities that belong to your country and create a new shape file with the selection named <code>your_country_places.shp</code>.</li>
<li>Load the <code>your_country.shp</code> file you had created in the previous exercise and compute the centroid for each Adminitrative level 1 in your country and export the layer to the file <code>your_country_centroids1.shp</code>.</li>
<li><p>Search for your place of birth among the most populated places. Where you born in a populated place? If not, identify the closest most populated place. To do so, use <a href="https://www.google.com">Google</a> or <a href="http://www.wikipedia.org/">Wikipedia</a> to find the latitude and longitude of your place of birth. Using your mouse and the <code>coordinate</code> window at the bottom</p>
<p><a href="../images/pics/GIS/QGIS-Coordinates.png"><img src="../images/pics/GIS/QGIS-Coordinates.png" alt="QGIS-Coordinates" style="width: 300px;" /></a></p>
<p>to search for your location of birth.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Better yet, using the <code>Plugins->Manage and Install Plugins</code> menu, install the <code>ZoomToCoordinates</code> plugin</p>
<p><a href="../images/pics/GIS/QGIS-ZoomToCoordinatesPlugin.png"><img src="../images/pics/GIS/QGIS-ZoomToCoordinatesPlugin.png" alt="QGIS-ZoomToCoordinatesPlugin" style="width: 800px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>and use it to find your place of birth as shown below <a href="../images/pics/GIS/QGIS-ZoomToCoordinates.png"><img src="../images/pics/GIS/QGIS-ZoomToCoordinates.png" alt="QGIS-ZoomToCoordinates" style="width: 800px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li>Compute the distance between your place of birth and both the closest centroid and the closest most populated place. If needed find a Plugin that will do the job for you. I recommend installing among many <code>realcentroid</code>, <code>mmqgis</code>, <code>coordinate capture</code>.</li>
<li>Generate the distance matrix among the most populated places</li>
<li>Generate the distance matrix between most populated places and the centroids</li>
</ol>
<h4 id="Note">Note<a class="anchor-link" href="#Note">¶</a></h4><p><em>Make sure you can correctly identify the features. For example using ISO codes, ID numbers, etc. If the shape file does not have an ID identifier, it is best to create one, so that you can correctly identify the features. To do so, use the <code>Field Calculator</code> by double-clicking on the name of the layer, then choosing <code>Fields</code>. After that you need to select the pencil icon to enable editing mode.</em></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Working-with-Rasters">Working with Rasters<a class="anchor-link" href="#Working-with-Rasters">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Let us load the Ramankutty raster using the <code>add raster layer</code> button in the toolbar.</p>
<p><a href="../images/pics/GIS/QGIS-add-raster-layer.png"><img src="../images/pics/GIS/QGIS-add-raster-layer.png" alt="QGIS add raster layer" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><code>Double-click</code> on the name of the raster in order to change the coloring scheme.</p>
<p><a href="../images/pics/GIS/QGIS-raster-color-scheme.png"><img src="../images/pics/GIS/QGIS-raster-color-scheme.png" alt="QGIS-raster-color-scheme" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>So it looks something like this</p>
<p><a href="../images/pics/GIS/QGIS-raster-with-color.png"><img src="../images/pics/GIS/QGIS-raster-with-color.png" alt="QGIS-raster-with-color" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Load your <code>your_country.shp</code> and <code>your_country_places.shp</code> on top of the Ramankutty data. It might look something like this.</p>
<p><a href="../images/pics/GIS/QGIS-Raster-KEN.png"><img src="../images/pics/GIS/QGIS-Raster-KEN.png" alt="QGIS-Raster-KEN" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Since we do not want to work with all the Ramankutty data, but only with the data for our country, let us <code>clip</code> the part of the Ramankutty data that belongs to our country. To do this, use the <code>Raster->Extraction->Clipper</code> tool.</p>
<p><a href="../images/pics/GIS/QGIS-Clipper.png"><img src="../images/pics/GIS/QGIS-Clipper.png" alt="QGIS-Clipper" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>In the window that comes up, choose a name for the clipped raster <code>suit_your_country</code> and choose the <code>save as GeoTiff</code> option, so that your file is saved as in GeoTiff format. Then click on the <code>Mask layer</code> button, make sure <code>your_country</code> layer is chosen as the mask. If you want choose a different <code>No data value</code>. Then click <code>ok</code>.</p>
<p><a href="../images/pics/GIS/QGIS-clip-KEN.png"><img src="../images/pics/GIS/QGIS-clip-KEN.png" alt="QGIS-clip-KEN" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>This will clip the Ramankutty data to the extent of your country of origin. Notice that in the big text box there is a command written, something like</p>
<pre><code>gdalwarp -q -cutline "gadm2.shp|layerid=0|subset=\"ISO\" = 'KEN'" -crop_to_cutline -of GTiff "suit/w001001.adf" GitHub/CompEcon/notebooks/QGIS/suit-KEN.tif
</code></pre>
<p>This is a the command QGIS uses to create the clip. QGIS is actually calling GDAL to perform this operation. This command line will be very useful when you are planning to use Python or other scripting languages to perform an operation many times. You can do it by hand once and copy the command executed by QGIS and use it to create an iterable version...more on this later.</p>
<h3 id="Note">Note<a class="anchor-link" href="#Note">¶</a></h3><p>You might have to assign a projection to the Suitability Raster. To do so, use the <code>Raster->Projection->Assign Projection</code> option in the menu.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>The output should look like this</p>
<p><a href="../images/pics/GIS/QGIS-KEN-Raster.png"><img src="../images/pics/GIS/QGIS-KEN-Raster.png" alt="QGIS-KEN-Raster" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Notice that given the large size of the cells in the raster, the clipping tool creates a lot of measurement error. It might be better to decrease the size of cells an then clip, so that the clipping is less erroneous. Let's try setting the cell size to $5''$ instead of $0.5^o$. To do so, <code>right-click</code> on the raster name and select <code>Save as</code>. Then set the <em>Resolution</em> to $5''=1/12=0.08333$ for both <code>Horizontal</code> and <code>Vertical</code>.</p>
<p><a href="../images/pics/GIS/QGIS-change-raster-size.png"><img src="../images/pics/GIS/QGIS-change-raster-size.png" alt="QGIS-change-raster-size" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now use the clip tool again. Much better! Obviously, the smaller the cell size, the more similar the clipped raster and the polygon will look like.</p>
<p><a href="../images/pics/GIS/QGIS-KEN-Raster5.png"><img src="../images/pics/GIS/QGIS-KEN-Raster5.png" alt="QGIS-KEN-Raster5" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Note:">Note:<a class="anchor-link" href="#Note:">¶</a></h3><p><em>Care has to be taken when converting raster's cells size, since values have to be interpolated. QGIS seems to have taken away your choice for setting it. Luckily, GDAL can help out. You can use its tools to change the cells size, the projection, clip, etc. We will see some tools in another lecture.</em></p>
<p>Let us use this raster to assign the average suitability in each administrative region. But before doing so, we need to reproject both the raster and shape files to a format that ensures the areas are correctly take into account. One such projection is the equal area projection. Right click on the raster or shape and select <code>save as...</code>. Then in the <code>CRS</code> option choose <code>Selected CRS</code> and click on <code>browse</code> and choose the following CRS (or create it if not present by using the <code>Settings->Custom CRS</code> menu)</p>
<pre><code>+proj=cea +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
</code></pre>
<p><a href="../images/pics/GIS/QGIS-Cylindrical.png"><img src="../images/pics/GIS/QGIS-Cylindrical.png" alt="QGIS-Cylindrical" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now save the file adding the postfix <code>cyl</code> so that you know it is the cylindrical equal area rojected one. Now, select <code>Raster->Zonal Statistics->Zonal Statistics</code>.</p>
<p><a href="../images/pics/GIS/QGIS-Zonal-Stats.png"><img src="../images/pics/GIS/QGIS-Zonal-Stats.png" alt="QGIS-Zonal-Stats" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Select the cylindrical versions of the raster and shape files and <code>suitcyl</code> as the <code>Output column prefix</code>. Now, in the attribute table you will find three new columns with the prefix <code>suitcyl</code> that show the <code>sum</code>, <code>count</code>, and <code>mean</code> suitability in in each feature. If you repeat the analysis with the unprojected (non-cyl) versions of the raster and shape files, you will see that the results vary (sometimes significantly). Whenever you do this type of analysis, it is important to make sure you are using the correct projection for the analysis.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Other-Raster-Tools">Other Raster Tools<a class="anchor-link" href="#Other-Raster-Tools">¶</a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>In the <code>Raster</code> menu you will find other useful tools to work with rasters. Especially useful is the <code>Raster Calculator</code>, with which you can do computations on one or more rasters.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Exercises">Exercises<a class="anchor-link" href="#Exercises">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ol>
<li>Import the Night Lights raster, convert it to a $5''$ raster, and clip it using your country's shapefile.</li>
<li>Compute the average light in each region in your country.</li>
<li>Generate a buffer of 100kms around each populated place and compute the average suitability and night lights for these buffers.</li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Adding-Information-and-Using-Colors">Adding Information and Using Colors<a class="anchor-link" href="#Adding-Information-and-Using-Colors">¶</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now that you have the average agricultural suitability for each administrative region. Let's color code it so we can visually observe the regional differences. For this double-click on the <code>your_country_cyl</code> layer, which should open a new window in the <code>style</code> tab of the <code>Layer->Properties</code> menu.</p>
<p><a href="../images/pics/GIS/QGIS-Style-Properties.png"><img src="../images/pics/GIS/QGIS-Style-Properties.png" alt="QGIS-Style-Properties" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now, click on <code>Single Symbol</code> and choose <code>Graduated</code>. This allows us to use colors to show the different values of a field/variable of interest.</p>
<p><a href="../images/pics/GIS/QGIS-Style-Category.png"><img src="../images/pics/GIS/QGIS-Style-Category.png" alt="QGIS-Style-Category" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Next let us select the field of interest in the attribues table, namely, <code>suitmean</code>. To do so, click on <code>column</code> and choose the variable/field of interest, inthis case <code>suitmean</code>.</p>
<p><a href="../images/pics/GIS/QGIS-Style-Field.png"><img src="../images/pics/GIS/QGIS-Style-Field.png" alt="QGIS-Style-Field" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>You can choose how many gradations to draw, e.g. increasing it from 5 to 10; change the color ramp, or the mode of creating the gradation. Try it out. You should get something like this</p>
<p><a href="../images/pics/GIS/QGIS-KEN-Graduated-suit.png"><img src="../images/pics/GIS/QGIS-KEN-Graduated-suit.png" alt="QGIS-KEN-Graduated-suit" style="width: 1000px;" /></a></p>
</div>
</div>
</div>
<script type="application/vnd.jupyter.widget-state+json">
{"state": {}, "version_major": 2, "version_minor": 0}
</script>
<script type="text/javascript">if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
var mathjaxscript = document.createElement('script');
mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
mathjaxscript.type = 'text/javascript';
mathjaxscript.src = '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
mathjaxscript[(window.opera ? "innerHTML" : "text")] =
"MathJax.Hub.Config({" +
" config: ['MMLorHTML.js']," +
" TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'AMS' } }," +
" jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
" extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
" displayAlign: 'center'," +
" displayIndent: '0em'," +
" showMathMenu: true," +
" tex2jax: { " +
" inlineMath: [ ['$','$'] ], " +
" displayMath: [ ['$$','$$'] ]," +
" processEscapes: true," +
" preview: 'TeX'," +
" }, " +
" 'HTML-CSS': { " +
" linebreaks: { automatic: true, width: '95% container' }, " +
" styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'black ! important'} }" +
" } " +
"}); ";
(document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
</script>
</div>
<!-- /.entry-content -->
<hr />
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
</div>
<!-- AddThis Button END -->
</article>
</section>
</div>
<div class="col-sm-3" id="sidebar">
<aside>
<section class="well well-sm">
<ul class="list-group list-group-flush">
<li class="list-group-item"><h4><i class="fa fa-home fa-lg"></i><span class="icon-label">Social</span></h4>
<ul class="list-group" id="social">
<li class="list-group-item"><a href="https://github.com/ozak"><i class="fa fa-github-square fa-lg"></i> Github</a></li>
<li class="list-group-item"><a href="https://twitter.com/OmerOzakEcon"><i class="fa fa-twitter-square fa-lg"></i> Twitter</a></li>
<li class="list-group-item"><a href="https://linkedin.com/in/omerozak"><i class="fa fa-linkedin-square fa-lg"></i> Linkedin</a></li>
<li class="list-group-item"><a href="https://www.researchgate.net/profile/Oemer_Oezak"><i class="fa fa-researchgate-square fa-lg"></i> Researchgate</a></li>
</ul>
</li>
<li class="list-group-item"><h4><i class="fa fa-external-link fa-lg"></i><span class="icon-label">Links</span></h4>
<ul class="list-group" id="links">