Friday, May 1, 2015

A Color Coded Election Results Precinct Map

Learning to use Python to make maps is becoming more fun the more time I spend with it.  This morning I was able to successfully generate a color coded precinct map showing which precincts were won by Alan Howze and John Vihstadt in last November's Arlington County Board election.

Here is what I did:
  1. Found a data set containing the election data.  The Virginia Department of Elections website has a CSV file with the data I needed here.
  2. Learned to use Python to extract the data I needed from this source.  This turned out to be surprisingly easy (maybe not so surprising, that's why I love Python!). I just needed the cvs module which comes with the standard library.  I then wrote a small script, precinct_winners.py, which produced a list containing the winner for each precinct.
  3. Wrote a script, vihstadt_howze_election_map.py, using mapnik and my precinct_winners.py script to generate a color coded map showing precincts which Howze won in green and those Vihstadt won in red.
Here is the resulting map:


I plan to spend the rest of my available time today trying to overlay Columbia Pike, the road along which the proposed streetcar that caused such a stir in this election had been planned to run.

I found a shapefile with all the roads in Arlington County here.  I'm planning to explore this file with the pyshp rather than the GDAL module, since pyshp is pure python instead of a wrapper around a C++ library and thus will be easier to work with.

My next post will report on my results.

No comments:

Post a Comment