In this tutorial I am only going to introduce Quantum GIS, or QGIS for short. Before proceeding here, please download and install QGIS on your computer. It is free. When you install it, do not install the extra data-sets unless you want to follow tutorials that use them (there are many tutorials for QGIS on the web, and generally they are free, too). Once installed, please start QGIS Desktop, not QGIS Browser.
NOTE: I initially wrote this tutorial years ago, using QGIS 1.7. As I write this update, QGIS has advanced to version 2.18.15. However the fundamental tutorial is still relevant; so it will remain largely unchanged while I develop some more advanced tutorials.
Shapefiles: What they are
A shapefile is a type of GIS file that contains geographic features (points, lines, and polygons) linked to a database. Each map feature has a unique identifier number, a “UID” or “FID”. The database, which looks like a spreadsheet of columns and rows, has a UID or FID column that links each record (a row) to each feature. Within each record, the database stores attributes of each feature, arranged as fields (columns). For example, a shapefile of property would contain polygons of each property in an area. The attributes of the polygons stored in the database might be:
a) the name of the owner,
b) the year the property was purchased,
c) the price of the purchase,
d) the allowable land uses for the property,
e) the area and perimeter length of the property, and
f) the property address.
HOWEVER, this information does not appear in a database automatically.
(1) A government must decide what information can be shared,
(2) the government must collect that information, and
(3) Planners must decide how to design the database. There are many different ways a GIS database can be structured, to this is a critically important design decision. The way you structure the data is part of the way you represent the city, and so a GIS database of a city is a kind of model of the city. The collection, distrubution, and structuring of the data are all policy decisions. Please keep this in mind as you learn GIS: it is not just a technical process, it is also a design process in which planners choose to represent and analyze their city in specific ways.
Structure of the Shapefile
Shapefiles are actually four (or more) separate files, which all have the same leading name, but different suffixes after the dot. For example:
mapname.cpg [the “codepage” tells QGIS to use UTF-8 character encoding for non-Latin scripts]
mapname.dbf [the database file that stores the attributes of each element.]
mapname.prj [a small text file that stores projection information]
mapname.shp [the graphic data: points, lines, and polygons]
mapname.shx [the index file that relates graphic elements to database records]
WARNING: all these files must be kept together in a single folder, and they all have to have the same leading filename in order for QGIS to read them together as a shapefile. Technically, a “shapefile” is all of these files, not just the “.shp” file that holds the geometric elements. That confuses a lot of new users. Standard practice in the internet is to zip all these files together, so that users will download all the files simultaneously. Which is good; but you should also heed the warning that when you unzip the files, keep them all together.
As a working example, please download this map of informal residential settlement areas in Kabul. Then you should unzip the files and store them in a folder.
A Little Data Management Advice
Any new software can be confusing to learn. But I have found that a whole separate challenge is the basic organization of data on your computer. If you are confident about how your organize your files, ignore this section. Otherwise, here are my suggestions:
1. Make folders with very short, but explanatory names.
2. Don’t use spaces or special characters (punctuation) in your folder names.
3. Store each set of shapefiles in a separate subfolder.
Here is an example of the pathname to where to store the shapefile I am providing:
Documents/geog/kabul/2001/2001_inf_flat.dbf
Documents/geog/kabul/2001/2001_inf_flat.prj
Documents/geog/kabul/2001/2001_inf_flat.shp
Documents/geog/kabul/2001/2001_inf_flat.shx
Start Using QGIS
QGIS opens with a blank map area.
Go to Layer > Add Vector Layer… and in the dialog box that opens, browse to the shapefile you have downloaded. Only one overall name of the shapefile will appear. It should look something like the image below:
Okay! You have loaded a shapefile into a GIS program!
Set the Coordinate Reference System (CRS)
Here is one of the really powerful features of GIS software. When it starts, QGIS just loads map data in an unprojected square grid, called a ‘Geographic’ projection. Any area which is far north or south of the equator will be visually distorted, unless you make the software display the map in a projection. Again, map projections are a whole field of specialty, but here we only need to know a few things:
1. The earth is a lumpy, irregular sphere. There are various mathematical models of this potato-shape. The standard geoid model used today is the Word Geodetic System of 1984, abbreviated as WGS84.
2. The most common projection for local urban maps is the Universal Transverse Mercator (UTM) projection, in which the Earth is projected onto a series of flat facets, resembling a dance-hall mirror-ball. The facet we need for Kabul is Zone 42 North.
Okay: now click on the bottom-right button that looks like a gridded sphere. This opens the “Project Properties” window with the second tab selected: “Coordinate Reference System (CRS)”.
This dialog gives you the option of selecting all the common (and uncommon) projections, and even the option of selecting your own, custom-designed projections. For this tutorial, we are going to find WGS84/UTM42N in this whole massive list. Later I will explain some shortcuts for finding it again. This time, scroll up to the top in this window and collapse all the boxes. It should then look like:
Now, you can see that we can select from a variety of Geographic, Projected, and User-Defined Coordinate Systems. UTM is a type of projection, so we can find it under the Projected CRSs. They are organized alphabetically, so you will find it hear the bottom. Open the “Projected” CRS folder and scroll down.
Even within the UTM projections, the ones which use the WGS datum are near the bottom (under “W”). Scroll down to those, and find the Zone 42 North CRS:
Once you find it, notice that it has an EPSG code next to it: 32642. EPSG stands for European Petroleum Survey Group. This organization gave a number code to almost all known projections, and now many people use those codes. To find this projection again, just type the number 32642 into the search field at the top of the dialog box, and this UTM projection will show up. Now that you have found it and selected it, check the upper-left box labeled “Enable ‘on the fly’ CRS transformation.” Then click OK.
In this case, the view only changes slightly. In some cases, the map disappears entirely! If the image disappears, go to View > Zoom Full and it will reset the view to see the full map. Here is why: when you first load the unprojected file, it assumes that the units are degrees. But in many maps, the units are in meters. If you look above, you will see that the scale bar shows 9,000 degrees! Considering that earth is only 360 degrees around, that is actually an impossible condition. But once you set the software to a projected view, your scalebar should be correct. In this case, it now shows 9 kilometers:
Now save this project (File > Save Project or Ctrl + S) which saves a small file that only includes this projected view and the shapefile loaded into it. When you restart QGIS later, you can go to File > Open Recent Projects and resume work on this projected shapefile. Now you can add more shapefiles as additional layers, and you can change their display settings, and you can do analyses and modifications of the data stored in the databases of each shapefile. Here, I am only going to show you very briefly how to get useable output from this project.
CREATE OUTPUT. Go to File > New Print Composer (Ctrl +P). This opens the Print Composer Window. Here, select the middle icon with the white ‘plus’ on a green circular field. Now, in the main left window, drag out a rectangle and a view of your working file will appear like this:
Now hover your cursor over the top-left icons in this window. Tooltips should reveal the function of each icon, in the following order from left to right:
1. Load from Template [this loads previously-designed Print Composer views]
2. Save as Template [this saves the present view as a Print Composer Template, or .qpt file]
3. Export as Image [this generates a raster output file such as a .jpg, .tif, .png, or .gif]
4. Export as PDF [this generates a Portable Document File]
5. Export as SVG [this outputs a Scaleable Vector Graphics file]
6. Print [this prints the composed view to your default printer]
You are welcome to print hardcopies (sixth button). To add a map to another document, however, you will probably choose button #3, and export as a JPEG or PNG. Here you can set the resolution/compression of your output image.Now you have a useable map image!
Now, you can go to the other pages listed under the GIS drop-down menu to learn where to get more data and how to do more with GIS. All these pages are very introductory, written to be intelligible to social scientists, not cartography specialists.