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.
There are various GIS specialized programs and packages. ESRI 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.
Nonetheless, I always suggest you use and learn open-source alternatives.
There are many open source GIS projects, many of which are supported/gathered at
Install QGIS using their installers. On OSX you may need to follow the instructions below.
If you followed the steps for installing the Continuum Anaconda Python Distribution and for creating the GeoPythonXenv
(presented here), then you are basically set for working with GIS in Python + R.
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 Canopy with all the pakages provided by Enthought. Additionally, you will need to install GRASS, QGIS, and GDAL/OGR.
There are various methods of getting these on your computer.
I used to install using the installers provided by Kyngchaos. But I have moved to using HomeBrew, which allows you install many other GNU projects. To do so, open a terminal window (I recommend getting iTerm2, 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)
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew doctor
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 brew install
command. Before doing so, you should run the following commands
brew update
brew tap homebrew/science
This will update HomeBrew's formulas to the latest version. Now issue the command
brew cask install qgis
You should be done and have teh latest vanilla version of QGIS
in your Applications folder.
Ok. sometimes you want QGIS
with all the additional blows and whistles, e.g. integration with GRASS
, 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 osgeo4mac and follow their instructions.
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 .profile
export GDAL_DATA=~/Library/Enthought/Canopy_64bit/User/share/gdal
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.
GIS comes in very different formats, althogh most of them can be categorizewd into two types Rasters and Vector formats.
There are many places to find data. Some useful links to start are:
See also Wikipedia links
Let us start by creating some simple maps. For this, create a directory called mydata
in your $HOME
directory and download the following datasets and extract them:
Doing so shows you the additional information contained in the shape file. For the GADM file it includes
OBJECTID
ID_0
ISO
NAME_0
ID_1
etc.
We can use this information to color our maps, or to select features for further analysis. I will use the select feature using an expression
button
'ISO'='KEN'
to select all features with Kenya's ISO-3 code.
This opens a window where you can write expression as the previous one, to select features by their attributes. These are SQL
expressions and have to conform to SQL
's grammar (we will not go into this at this point). Once I execute the same expression as above
'ISO'='KEN'
QGIS leaves only the features in Kenya for analysis.
Other important tools can be found in Layer -> Properties
or by double-clicking
on the layer's name
The Vector
menu has many tools that can be applied to vector layers. Let's use some of these to create new layers.
Using the Vector -> Geometry Tools -> Singlepart to Mutliparts
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.
your_country_places.shp
.your_country.shp
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 your_country_centroids1.shp
.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 Google or Wikipedia to find the latitude and longitude of your place of birth. Using your mouse and the coordinate
window at the bottom
to search for your location of birth.
realcentroid
, mmqgis
, coordinate capture
.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 Field Calculator
by double-clicking on the name of the layer, then choosing Fields
. After that you need to select the pencil icon to enable editing mode.
In the window that comes up, choose a name for the clipped raster suit_your_country
and choose the save as GeoTiff
option, so that your file is saved as in GeoTiff format. Then click on the Mask layer
button, make sure your_country
layer is chosen as the mask. If you want choose a different No data value
. Then click ok
.
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
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
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.
You might have to assign a projection to the Suitability Raster. To do so, use the Raster->Projection->Assign Projection
option in the menu.
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, right-click
on the raster name and select Save as
. Then set the Resolution to $5''=1/12=0.08333$ for both Horizontal
and Vertical
.
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.
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 save as...
. Then in the CRS
option choose Selected CRS
and click on browse
and choose the following CRS (or create it if not present by using the Settings->Custom CRS
menu)
+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
Select the cylindrical versions of the raster and shape files and suitcyl
as the Output column prefix
. Now, in the attribute table you will find three new columns with the prefix suitcyl
that show the sum
, count
, and mean
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.
In the Raster
menu you will find other useful tools to work with rasters. Especially useful is the Raster Calculator
, with which you can do computations on one or more rasters.