jjguy / heatmap

Python module to create heatmaps
MIT License
142 stars 52 forks source link

calculate bounding box for geo maps #21

Open Henner opened 10 years ago

Henner commented 10 years ago

whats the best way to calculate the bounding box for a heatmap of geo points (lng/lat)? The auto calculated way cuts off the circles at the edges of the image...

Henner commented 10 years ago

see example: http://demo.stage.miadi.net/heatmaps/heatmap.html

kwauchope commented 10 years ago

I dynamically set the width and height based on a selectable value 'pixels per degree' (PPD). I then scale this with an upper bound of 8192 which is based of the maximum texture size of the google earth client. Select your preferred PPD based on what quality image you are after/how far in you intend to zoom.

      width = int((east - west)*PPD + dotsize/2)
      height = int((north - south)*PPD + dotsize/2)
      largestVal = max(width,height)
      if largestVal > MAX_SIZE:
         scale = float(MAX_SIZE)/largestVal
         height = int(height*scale)
         width = int(width*scale)
         PPD = float((width-dotsize/2))/(east-west)
      dotDegrees = dotsize/2/PPD
      bounds = ((west-dotDegrees, south-dotDegrees),(east+dotDegrees,north+dotDegrees))
kwauchope commented 10 years ago

Updated above post with somewhat tested code. Considering adding it as a method in heatmap.py.