heatmap icon indicating copy to clipboard operation
heatmap copied to clipboard

calculate bounding box for geo maps

Open Henner opened this issue 11 years ago • 3 comments

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 avatar Jul 11 '14 17:07 Henner

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

Henner avatar Jul 14 '14 11:07 Henner

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 avatar Jul 26 '14 05:07 kwauchope

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

kwauchope avatar Aug 03 '14 15:08 kwauchope