Creating heat map using GeoDjango
GeoDjango is a Django module that turns it into a web-GIS app. It is powerful as it uses geospatial engines such as GDAL, GEOS and PostGIS.
In this post, we'll be creating heat map using leaflet plugin https://github.com/Leaflet/Leaflet.heat.
From our views.py, we need to create a function that can return JSON object with this format:
[[50.5, 30.5, 0.2], // lat, lng, intensity [50.6, 30.4, 0.5],]
Below is an example:
Basically, the proposed_roads query uses the Centroid function of GeoDjango, also intensity is obtain by getting the sum (change this depending on your specification or needs) based on the subquery. The output of this query is intensity and the Point object derived from Centroid which is named as "cent".
To turn it into the desired format, we need to convert it into list and append the intensity (which is the 3rd value). The function returns a JSON data similar to the required format of leaflet heatmap.
You can then use AJAX in the front-end:
Adjust the radius, blur and the gradient values and color depending on your need.
Comments
Post a Comment
Feel free to ask, suggest and comment regarding this post/blog. You can also contact me through e-mail, just always use the contact page. Thank you for visiting this blog.