Creating heat map using GeoDjango

 

heat map
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

Popular posts from this blog

A Better Archive Page for Blogger

Publish PostGIS Layers in GeoServer Automatically using cURL and REST

BECK Live Action