Map and visualizations of new districts and open seats
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
data
map
scripts
tilemill
.gitignore
LICENSE.txt
README.md
fabfile.py
project_dirs.py.example

README.md

Data analysis and interactive map for Minnesota's 2012 districts

Methodology

Our PVI is a Minnesota-specific version of the Cook Partisan Voting Index (CPVI), which measures how strongly a geographic area leans toward one political party.

Each district is assigned a PVI value, which shows its political leaning. R+12, for example, denotes that district leans Republican by 12 percentage points, whereas D+2 would represent a two percentage point leaning toward the Democratic party. EVEN means a political leaning of less than one percentage point.

Our calculations use the three most recent state house races: 2006, 2008 and 2010.

Using a spatial database process, we matched up each precinct to its newly assigned district. For example, a precinct with a geometric centroid in district 21A would be considered part of that district.

We then add up the total votes for each party per 2012 district, for each race. These numbers are turned into a PVI index as follows:

100 * ((Votes for a republican candidate / Total number of votes) - (Votes for a democratic candidate / Total number of votes))

This is calculated for each race. The average of these gives the overall PVI used in our visualization. These numbers are then rounded to the nearest whole number and assigned a party for readability.

For the technical details, check out our scripts.

Data

Data Manipulation

Bounding Box

Import L2012-shp.zip into PostGIS: shp2pgsql -d data/L2012-shp/L2012 redistricting_map | psql -U postgres -h localhost -d minnpost

Query to get Bounding Box (Enveloper): ``` SELECT district, ST_AsGeoJSON(BOX2D(ST_Transform(ST_SetSRID(the_geom, 26915), 4326)), 4) as geom FROM redistricting_map;


Converted this output to CSV, then to JSON with csvjson (csvkit).

#### Pvi calculations
Get data in line:

mkdir -p originals cp *.xls originals in2csv 2006_general_results.xls > 2006_results.csv in2csv 2008_general_results.xls > 2008_results.csv in2csv 2010_General_Results_Final.xls > 2010_results.csv python prep.py python calculate.py


Use fabfile.py functions:

```fab setup_shapefiles``` 

```fab enter_precincts_shapefile:{2002,2002_sen,2010,2012_sen}```

```fab calculate_shapefile:{2002,2002_sen,2010,2012_sen}```