How to group latitude/longitude points that are 'close' to each other?

前端 未结 5 614
星月不相逢
星月不相逢 2021-01-31 09:30

I have a database of user submitted latitude/longitude points and am trying to group \'close\' points together. \'Close\' is relative, but for now it seems to ~500 feet.

5条回答
  •  轮回少年
    2021-01-31 09:34

    There are a number of ways of determining the distance between two points, but for plotting points on a 2-D graph you probably want the Euclidean distance. If (x1, y1) represents your first point and (x2, y2) represents your second, the distance is

    d = sqrt( (x2-x1)^2 + (y2-y1)^2 )
    

    Regarding grouping, you may want to use some sort of 2-D mean to determine how "close" things are to each other. For example, if you have three points, (x1, y1), (x2, y2), (x3, y3), you can find the center of these three points by simple averaging:

    x(mean) = (x1+x2+x3)/3
    y(mean) = (y1+y2+y3)/3
    

    You can then see how close each is to the center to determine whether it should be part of the "cluster".


    There are a number of ways one can define clusters, all of which use some variant of a clustering algorithm. I'm in a rush now and don't have time to summarize, but check out the link and the algorithms, and hopefully other people will be able to provide more detail. Good luck!

提交回复
热议问题