Algorithm for heat map?

后端 未结 4 1844
梦如初夏
梦如初夏 2021-01-31 12:04

I have a list of values each with latitude and longitude. I\'m looking to create a translucent heatmap image to overlay on Google Maps. I know there are server side and flash

相关标签:
4条回答
  • 2021-01-31 12:27

    A faster way of building a heatmap could be to use a queue:

    Pseudocode:

    Add an element to queue (first in heatmap(x,y, val))
    While (!queue.isEmpty())
    {
        elem = queue.pop()
        queue.push(elem.x + 1, elem.y, val-1)
        queue.push(elem.x - 1, elem.y, val-1)
        queue.push(elem.x, elem.y + 1, val-1)
        queue.push(elem.x, elem.y - 1, val-1)
    }
    

    This saves on tons of iterations!

    0 讨论(0)
  • 2021-01-31 12:30

    Look at this project if you are looking for something that looks more like 'tv weather maps':

    https://github.com/optimisme/javascript-temperatureMap

    0 讨论(0)
  • 2021-01-31 12:37

    The basic idea would be to create a grid and project every lat,lng coord to that grid. I would use a 2D array of ints.

    The psuedo-code would be:

    for each coord
      cell = coord projected to grid
      increment cell value
    end
    
    for 0 to # of passes
      for each row
       for each col
         if grid[row,col] > 0 then
           grid[row,col] += 1
           increment_adjacent_cells(row, col)
         end
       end
      end
    end
    

    So, the idea is that the higher the int value, the hotter that cell is. increment_adjacent_cells should increment the values in all 8 adjacent cells.

    0 讨论(0)
  • 2021-01-31 12:51

    I have tried to solve this in javascript using the canvas element, here is my current result:

    http://gist.github.com/346165

    I have to fix the gaussian filter and the color mapping, because it doesn't give good results currently.

    0 讨论(0)
提交回复
热议问题