From charlesreid1

Installing

To install QGIS on Mac OS X:

First, I went to the download site on QGIS website:

http://www.qgis.org/en/site/forusers/download.html

I was pointed to the KygChaos wiki http://www.kyngchaos.com/software/python

At that wiki, I downloaded several provided dmg files:

  • Numpy
  • Matplotlib
  • GDAL framework
  • QGIS

I installed each, in that order. The python libraries that are being installed install to /Library/Python/2.x/site-packages - which is where libraries available to the SYSTEM version of Python are available. This will not interfere with existing versions of numpy or matplotlib libraries that you've installed using an Anaconda or Python.org or Homebrew (or other) version of python that you have installed.

Once all of those installers had been run, I opened QGIS in my Applications folder.

QGIS First.png

Basics

Opening Shapefiles

To open a shapefile, you can create a project. Then you can click the first icon in the left-hand menu, the dots connected by lines (Add a Vector Layer). Here, you can pick "ESRI Shapefile" from the drop-down menu, and you'll be able to open shapefiles.

Here's an imported shapefile of military installations in the United States (from the Harvard Library website):

QGIS Shapefile.png

Adding Tiles

Figured most of this out thanks to the QGIS wiki, [1]

The shapefile on its own probably isn't very interesting. You can add the OpenLayers plugin, which allows you to bring in map layers from Google Maps, OpenStreetMap, Bing Maps, etc.

QGIS Plugins.png

If we now go to Web > OpenLayers plugin, we can pick from a list of different map layers provided by different services!

Now I see a much more interesting map of military installations:

QGIS Military.png

By right-clicking on the layer and selecting properties, you can make the polygons transparent and change their colors:

QGIS Military2.png

Visualizing Quantitative Maps

This covers how I made and visualized a quantitative map.

Creating a Quantitative Map with Python

To test out the capabilities of QGIS for creating quantitative maps, I started with each county in California. I obtained GeoJSON for each of the 58 counties using the Census Reporter API. The API call looks like this:

$ curl "http://api.censusreporter.org/1.0/geo/show/tiger2013?geo_ids=050|04000US06"

This means every county (050 is county level) in the state (040 is state level) in state number 06 (California).

This returns a dictionary with the following structure:


{
    "geometry": {
        "coordinates": [
            [
                [
                    [
                        -122.07282000000001,
                        41.183097
                    ],
                ]
            ]
        ],
        "type": "MultiPolygon"
    },
    "properties": {
        "geoid": "05000US06089",
        "name": "Shasta County, CA"
    },
    "type": "Feature"
}

If we add fields to the "property" dictionary, we can use those properties to control map styles, meaning we can start to visualize data.

I'll start by giving each county a random number, and using that to control the color when I make a map of each county:

import json
import urllib2

url = "http://api.censusreporter.org/1.0/geo/show/tiger2013?geo_ids=050|04000US06"
 
county_names = json.load(urllib2.urlopen(url))

for ii,conty_names in enumerate(county_names):

    derived_quantity = np.random.rand()*10

    counties['features'][ii]['properties']['derived_quantity'] = derived_quantity



with open('ca_derived_quantity.geojson','w') as f:
    f.write( json.dumps(counties) )

print "bing! all done!"

Using Properties to Control Map Style

I can start by adding an OpenLayers tile layer to show me the United States in context. Next, I add a vector layer, and add the JSON file I created with the script above, ca_derived_quantity.geojson.

Now I right click on the vector layer that is created, and pick Properties. I can use the field "derived_quantity" to control the map color:

QGIS DeriviedQuantityColor.png

and then map it:

QGIS DerivedQuantityMap.png