Plotting aggregated geolocation data points onto a map as a heatmap is a common thing to do and there are a handful of libraries supporting this. In this blog, I’ll note down my experiments in plotting weighted geoheatmap using two most common libraries: gmaps and folium.
The simplicity of folium may result it to be the first tool many people picks when it comes to plotting geoheatmap, however, the weighted heatmap is not working properly and the visualisation will give you incorrect results by ignoring the weight column in your datum. Therefore, when you need to plot weighted heatmap, pick another library like gmaps and let google map API do the rest for you, just as easy as that. Below is the post for the folium weighted heatmap bug.
Then I turned to gmaps and it yields correct output for weighted geo-heatmap. Minimum code is as below:
#data.csv looks like this:
+-----------+--------------------+---------------+
| lat | long | weight |
+-----------+--------------------+---------------+
| 64.27 | -21.65 | 100 |
| 64.27 | -21.58 | 200 |
| ... | ... | ... |
+-----------+--------------------+---------------+import gmaps
import pandas as pddata = pd.read_csv('data.csv')gmaps.configure(api_key="AI...") # Fill in with your API keym = gmaps.Map()heatmap_layer = gmaps.heatmap_layer(data[['lat','long']], weights=data['weight'],max_intensity=10000, point_radius=20.0
)#point markers layer:markers = gmaps.marker_layer(store_locationlist)
m.add_layer(markers)m.add_layer(heatmap_layer)
m
To get API key from google map services is straightforward, it only requires you to use the map services from google, do note that the google map API may incur charges according to their price plan, but if you are crafting out your personal project in relatively small scale, it should fall into the free tier.
https://developers.google.com/maps/documentation/javascript/get-api-key
Voila! There you have it, a weighted geo-heatmap (Iceland as example because it’s a nice place)
Cheers!