ADMINS
Kenton Ngo
Johnny Camacho
Aimee Fausser
EDITORS
Bryan Scrafford
Adam Sharp
DanielK

BlogRoll
STATEWIDE
Bearing Drift
Blue Commonwealth
BlogNetNews
CobaltVA
Not Larry Sabato
Raising Moran
VAPoliticalBlogs

NORTHERN
7 West
Albo Must Go
Anonymous Is A Woman
Anti-BVBL
Blacknell
Blueweeds
Getting Around
Leslie Byrne
Left of the Hill
Ox Road South
Raw Fisher
Renaissance Ruminations
The Green Miles
Too Conservative
X Curmudgeon

HAMPTON ROADS
Shad Plank
VBDems
Vivian Paige

CHARLOTTESVILLE
Democratic Central
Rick Sincere
Rule .303
Shaun Kenney
Waldo Jaquith

RICHMOND
SlantBlog
Save Richmond
Tertium Quids

SOUTHSIDE
Dem Bones
What IS Right For Virginia
220 South

VALLEY
Adam Sharp
RockDem
The Friendly City
The Valley Progress Report

SOUTHWEST
Rick Howell Speaks
Star City Harbinger

Creating Choropleth Maps Using Freeware

by: Kenton Ngo

Tue Dec 08, 2009 at 11:39:08 AM EST


I've often been asked how I generate those colorful maps I spit out whenever I don't feel like writing. In this post I will show you how, using open-source GIS software, you too can create those maps. Over the years I've cobbled together a process using an ever-evolving set of software (which a cash-strapped high school, now college student could afford--that is, free). Right now I use a program called Quantum GIS.

Download Quantum GIS for Windows, Mac, and Linux here.

For this example, we will be mapping county-by-county election results for the 2006 gubernatorial election in Massachusetts (which has a small number of counties, so it is simple.)

You can obtain shapefiles from the Census Bureau here and here. Shapefiles are often freely available from your municipal government's GIS department. If it exists, someone has probably made it into a shapefile. For this example, we'll use this shapefile (ZIP archive 41,372 bytes).

Kenton Ngo :: Creating Choropleth Maps Using Freeware

Data - The Shapefile

The shapefile is the most popular form of vector spatial data. Technically, it refers only to the .shp file extension (which contains the actual points or polygons), but it typically refers to the whole collection of the .shp and related files. When you download a shapefile package and open it up, you'll often see a few files like so:

The .shp file is a collection of either points, polygons, or polylines. Points can be polling places, polygons can be precincts, and polylines can be rivers. In creating choropleth maps you will most likely be using polygon shapefiles. The data about those polygons is contained in the .dbf file that is always bundled with the .shp.

Before you manipulate the DBF file, I recommend creating a backup. Open the .dbf in Excel. It'll look like this:

Every DBF will be different, but most follow a similar structure. Each row corresponds to one of the polygons in the shapefile.

Area and Perimeter - These are generated when the shapefile is generated and are irrelevant.

CO25_D00 and CO25_D00_I - These are sequentially numbered columns that tell you what order the shapefile rows are in. These are VERY IMPORTANT. IF YOUR DBF DOES NOT HAVE A SEQUENTIALLY NUMBERED COLUMN, YOU WILL NEED TO CREATE ONE. In a new column, type "1" in the first row and go to Edit -> Fill -> Series to create a sequentially numbered column. Sortation order in the corresponding .shp file is ABSOLUTE, so you MUST place the DBF rows in the original order before you save it!

State - When working with government-issued shapefiles, we will often encounter FIPS codes. Each geographic unit in this country is assigned a FIPS code-"25" is the FIPS code for Massachusetts and "51" is for Virginia.

County - FIPS code for the county.

Name - County name.

LSAD - Geographic type identifier-06 is county.

LSAD_TRANS - Explains the LSAD column.

Now we sort the DBF file by county name so we can paste in the election margins. If you are working with percentages, it is important you leave them in decimal format. I subtracted the Republican results from the Democratic results--Democrat is positive, Republican is negative:

Notice how some of the counties in the DBF are duplicated-in this example, Bristol, Dukes, and Norfolk. Islands are their own polygon, so they get their own row-single counties can comprise of multiple polygons. You will have to duplicate that data like so:

Delete the duplicate names column and sort the file by the sequence column:

Save this file as a CSV file. .dbf is a very finicky format, and if you save directly to a DBF using Excel your edits will be lost (don't ask why, I don't know). Close the file.

Open the CSV, resize the columns (if your columns are too narrow, it will truncate the columns in the DBF). Make sure your data column is in a consistent format:

Save this file as a DBF. Overwrite the old file-it is very important your DBF and SHP have 1) the same name and 2) are in the same directory. Now we are ready to map.

Map - Creating the Choropleth


Open qGIS and add a layer.

Each shapefile serves as its own "layer"-you can overlay them on top of each other. For example, if you are mapping by precinct you can overlay congressional district boundaries. We'll keep this example simple and have only one layer.

Hit "Browse" in the popup dialog and find your .shp file. Bam! Massachusetts!

This, however, is boring. Go to the layers panel on the left, right-click the layer and go to Properties, and go to the Symbology tab. Under "Legend Type", select "Graduated Symbol".

Under "Classification Field", select what you called your data column, and under number of classes input the number of colors you want. Then hit "Classify."

Double-click each class on the left to change its boundaries. Since this is a margin column, negative numbers are Republican counties and positive numbers are Democratic counties. Let's split them up by counties won by party, and then whether the county was won by 10 or more points. Clicking on "Fill color" will give you a panel of colors to choose from for each class. Don't forget your data is in decimal format! Hit "OK".

And you'll see this:

Go to File - > Save as image, and you'll have an image you can import into your chosen image editor before you share your creation with the world.

Questions? Email me. If I have time I will try to help you-writing instruction guides isn't my strong suit, so you are encouraged to leave a comment here or email me with suggestions. We have only scratched the surface of what we can do with this very simple example. Comment or email with your experiences and what you've put out.

Coming up later: 3-D maps using Earth, and other fun tricks for refining your maps. Stay tuned!

Tags: (All Tags)
Print Friendly View Send As Email
Recent Diaries
affordable seo
by: iiiirt2 - May 12

Menu

Make a New Account

Username:

Password:



Forget your username or password?


Syndicate
RSS 2.0
Tip Jar

EMAIL
Send tips & press releases to:
[email protected]

Search




Advanced Search


LeftyBlogs Latest

The views expressed on this site are representative solely of the author, and do not necessarily imply endorsement by New Dominion Project staff.
Powered by: SoapBlox