I am looking to build a static KML (Google Earth markup) file which displays a heatmap-style rendering of a few given data sets in the form of [lat, lon, density] tuples.
<
I think one way to do this is to create a (larger) list of tuples with each point repeated according to the density at that point. A point with a high density is represented by lots of points on top of each other while a point with a low density has few points. So instead of: [(120.7, 82.5, 2), (130.6, 81.5, 1)]
you would use [(120.7, 82.5), (120.7, 82.5), (130.6, 81.5)]
(a fairly dull dataset).
One possible issue is that your densities may well be floats, not integers, so you should normalize and round the data. One way to do the conversion is something like this:
def dens2points (dens_tups):
min_dens = dens_tups[0][2]
for tup in dens_tups:
if (min_dens > tup[2]):
min_dens = tup[2]
print min_dens
result = []
for tup in dens_tups:
for i in range(int(tup[2]/min_dens)):
result.append((tup[0],tup[1]))
return result
if __name__ == "__main__":
input = [(10, 10, 20.0),(5, 5, 10.0),(10,10,0.9)]
output = dens2points(input)
print input
print output
(which isn't very pythonic, but seems to work for the simple test case). This subroutine should convert your data into a form that is accepted by heatmap.py. With a little effort I think the subroutine can be reduced to two lines.