An interactive map that asks readers to say where they're from and where "up north" is to them? Responses are analyzed to show what parts of Wisconsin readers as a whole think of as "up north."
Under the hood, there are three parts to the interactive, each with an associated folder in this repo:
frontend/
: webpage that readers seetally/
: backend app that collects reader responsesprocess-votes/
: heat map generator
This is the webpage that shows the map, asks you to draw the line for "up north" and enter where you're from.
After you respond it shows you the heat map of all readers' responses, which is created in process-votes/
folder.
Most of the work is done with D3.js. The code is built with webpack. See
frontend/README.md
for instructions on how to develop and build the code.
This is a flask app that collects responses from readers. It uses the peewee library to manage the response data in a SQLite database.
First thing you'll need to do is create the database. In the tally/
folder, open up python and enter:
from models import create_database
create_database()
The database contains one table, votes, which has five columns:
_id
: unique ID for a vote (automatically generated)timestamp
: when the vote was castvalues
: comma-separated list of eight latitudeslocation
: where the reader is from, ie., the county in Wisconsin or state name if not a Wisconsinitebrowser
: hash of user agent and IP address of poster
The values
field defines the line the user drew. A line consists of eight points with fixed longitudes and variable latitudes, which the reader can adjust. Only latitudes are stored in the database
because the longitudes don't change.
The browser
field is used later on to prevent one person from posting a bunch of times and skewing the results.
The API has two routes. One for posting a vote (/api/vote
) and one for getting all votes (/api/votes
). The vote posting data
should look like: { v: values..., l: location... }
.
This pulls in reader responses and creates a heat map showing where most Wisconsinites think "up north" is.
The main script is bin/process-votes.sh
, a bash script with a series of commands. This is run periodically as a
cron job. The end result is a PNG of the heat map, output/up-north.png
, which is accessed by the frontend webpage
to display the response of readers as a whole.
Here's a summary of the commands:
node bin/get-votes.js
- downloads reader responses from the
tally/
API - removes duplicates
- creates
votes.json
- downloads reader responses from the
python bin/aggregate-area.py
- creates an "up north" polygon for each reader's response
- burns all of these polygons into a raster
gdal.RasterizeLayer(raster, [1], polygons, burn_values=[1], options=['MERGE_ALG=ADD'])
- this creates a raster where if 56 polygons overlap in one spot, the value for that pixel will be 56
- write the aggregation raster to file as a GeoTIFF
gdal_translate
: shrink the GeoTIFF to a more managable sizenode bin/colorize.js
: convert from 1-band sum values to 3-band color (white = few; green = many)gdalwarp
: cut the GeoTIFF to the border of Wisconsingdalwarp
: reproject to mercatorgdal_translate
: convert from GeoTIFF to PNG