Skip to content

benelan/choroator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Choropleth Map Creator

The United States Choropleth Map Creator was made by Ben Elan for a final undergraduate project in Spring 2018. The project takes a user's CSV file as an input and creates an interactive Leaflet map to be displayed in a web browser.

Prerequisites

To run the script you must have Python 3 installed. You also need a few Python packages which can be installed from the terminal (once Python is already installed) by typing:

python3 -m pip install pysal==1.14.4
python3 -m pip install pandas==1.3.3
python3 -m pip install folium==0.7.0

If you are having trouble with pip visit their website.

Creating the CSV

There are some example CSV files included in the repo. If you wish to use your own data the format must be the same.

CSV Format:

  • Header (first row): Category,Units,Source (ie. Average Income,Dollars,data.gov)
  • Data (the rest): State,Data (ie. California,53489)

It is okay if you don't have data for every state. Leaving out state rows in the CSV will be handled properly.

The Python Scripts

There are three python files located in the python directory:

dataImport.py

This is the command line version. Name the CSV file you wish to use data.csv and place it in the data/csv directory. Alternatively, change the file path in the script. If one of the command line arguements is misspelled or omitted the default values are chosen. The script takes 5 command line arguments with the following options:

Data classification (web only)

  • 'quantile' (Default)
  • 'jenks'
  • 'percentile'
  • 'equal' (Equal Interval)
  • 'natural' (Natural Breaks)

Color palette

  • 'blue' (Default)
  • 'green'
  • 'red'
  • 'gold'
  • 'purple'

Basemap

  • 'satellite' (Default)
  • 'dark'
  • 'light'
  • 'streets'
  • 'outdoors'

Map type

  • both (Default)
  • 'folium'
  • 'web'

Data normalization (web only)

  • none (Default)
  • 'density' (divides by state's area)

Note: when normalizing by area, 'District of Columbia' is omitted from the pysal classsifaction functions

Example runs

Defaults to quantile, blue, satellite, no normalization, creates both maps:

python3 dataImport.py

Equal interval, color defaults to blue due to misspelling, light basemap, no normalization, creates both maps:

python3 dataImport.py equal ultraviolet light

Jenks classification, gold color scale, dark basemap, normalized data based on area, only creates a web map:

python3 dataImport.py jenks gold dark density web

app.py

This GUI is built using TKinter. The app first prompts you to choose a CSV file. The path defaults to the choropleth/data/csv directory but you can chose a file from anywhere on the computer. There are two tabs to chose from, Web and Folium. You are then given the same options described above in GUI format.

python3 app.py

createMap.py

This script contains two functions.

Web

Creates an output GEOJSON to be used with a web version of the Leaflet map. The GEOJSON is used in the index.html and map.js files. This option has the most functionality.

Folium

This uses a Python package called Folium to create a Leaflet map which bypasses the need for creating a new GEOJSON and using HTML or JavaScript.

The Folium map does not have interactivity and the data classification and density options do not currently work. The breaks are set to quantile by default.

TODO

To do list

  • add iframe support
  • scale text doesn't show up on dark basemaps for folium (somehow change css class to 'leaflet-bar')
  • add class break support to folium
  • add density support to folium
  • use pandas for the web function
  • add a population normalization option
  • start integrating county GEOJSONs

Built With

Data Sources

About

United States Choropleth Map Creator takes a CSV as an input and creatives an interactive Leaflet map.

Topics

Resources

License

Stars

Watchers

Forks