Python server side heatmap library demo
-
install heatmap
$ cd heatmap-2.2.1 $ python setup.py install
-
install PIL
$ sudo easy_install Pillow
$ python lib/python-heatmap/test.py
- This script takes a series of points from a JSON file.
-
From Apache web server navigate to
http://<your.host>>/twine-heatmap/index.html
-
If no heatmap is visible, check permissions (enable shell_exec and r/w "imgs" folder)
-
Currently the twine.heatmap.py service is not a Rest API, it uses twine.heatmap.php to accept requests and run the twine.heatmap.py script.
-
The script accepts the following params;
- png: (boolean) - determines wether or not to generate a python PNG heatmap or return an array of [lat, lon] coords to the client. - dotSize: (int) - the dot size of each cluster based on the Python server side heatmap library. - opacity: (int) - the opacity to set the generated heatmap layer. - imgSize: ([width, height]) - image size of PNG to generate. - bounds: ([width, height]) - bounds of image to generate.
-
The script returns either;
-
filename of the image located on the server (filename is unix timestamp), added to Leaflet map using L.imageOverlay;
L.imageOverlay('imgs/' + response.filename + '.png', [[bounds[0][0],bounds[0][1]],[bounds[1][0],bounds[1][1]]]).addTo(map);
-
[lat, lon] points to display on the client;
var heatmapLayer = L.heatLayer(response.data, options).addTo(map);
-
-Several improvements are required to make this proof of concept a reliable service.
-
Implement Python script as Rest API with default set of options.
-
Run cleanup script to remove generated PNG heatmap images from server.
-
Request point data from PostGIS indexed db using ST_Contains query.
-
Provide the "scheme" as an option for the generated PNG heatmap image (available options from Python heatmap library as below include one of ["fire", "classic", "omg", "pbj", "pgaitch"].
- At zoom levels greater than 7 (where the world is at full extents as zoom level 0), the client transitions from displaying server side PNG generated heatmap to leaflet.heat client generated heatmap.