## Generating Choropleth Maps

Stephen Duncanson
December 28, 2019

Another project of mine that started during my internship at RACE Coastal Engineering was creating kml polygonal heatmaps from lists of (lat,long) coordinates. An example of this is shown below using randomly generated coordinates: random.uniform(41,42), random.uniform(-71,-72) and 1-mile side lengths.

Polygonal heatmap generated from randomly generated latitude and longitude pairs around CT. Source: heat.py. kml file: test.kml

This heatmap program was heavily inspired by Mark Polczynski and Michael Polczynski's paper: A Microsoft VBA Application for Generating Heat Maps, in which they analyze the 17th century frontier between the Polish/Lithuanian Commonwealth and the Ottoman Empire. I reimplemented their algorithm in python for increased speed and flexibility.

In both cases the steps are the same:

1. Generate a grid of geographical regions
2. Calculate a g grid attribute value for each square
3. Build KML polygon layer, coloring squares accoridng to their g values

Each 'square' has a g value defined as:

g_{i} = sum_(j=1)^N p_{j} e^{-\frac{d_{ij}^{2}}{r^{2}}

Where N is the number of squares on the map, p_{j} is a constant denoting the weight of the point (in the case of the heatmap p_{j} = 1), d_{ij}  is the distance between the center of the square and the set of coordinates, and r^{2} is what the paper calls the grid range which changes the look of the heatmap.

Eventually this will be given proper treatment, for now it serves to illustrate the power of KML. There are myriad improvements which could be done to my program (a kdtree for starters).

To be continued...