# Weighted clustering of lat lon coordinates

I have millions of lat long points that have been grouped into squares. Some squares have thousands of points, others have a couple of points. The idea is that we have one set of lat long for the square with a weighting related to the square based on the number of items it has instead of having millions of rows of data to the cluster.

I was originally using the leadercluster algorithim which allowed me to specify the distance each of my clusters should cover. This is ideal for my use case but now I would like to use it to cluster squares factoring in the weight of the squares. This is basically a learning experience for me and any help would be greatly appreciated

I have seen this which could be useful but I'm not really able to make headway with it

Below is some sample data in R about airports and arrivals

df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')

ggplot(df, aes(x = long, y = lat)) + geom_point()

sample <- df %>% select(long, lat, arrivals = cnt)


## 1 Answer

Leader clustering is so simple, the weight does not make a difference.

It assigns points to a cluster if the distance is less than a threshold. It does not matter whether the point has 1 weight or is a "square" of 100.

• Hi @Anony-Mousse, I like the algorithm very much because it scales well. However our IT architects have reasonably told me they cannot give me a million data points every 1/4 or so for a learning experience. What they can give me is a grid of 10*10 square meters of the area I'm interested in tell me how many points are contained within each of those squares. This will reduce the data by almost a factor of 20. I want to cluster these squares instead where the weighting will be attached to the number of items contained within a square........ Sep 19, 2017 at 7:50
• ......The square itself will have a centroid of a single lat-lon coordinate. In the example above i have approximated the problem by using an airport dataset where each airport has a number of arrivals. The more arrivals in that airport, the higher the pulling power of that airport/square Sep 19, 2017 at 7:52
• Well, you can't use Leader well on a grid map. Because Leader only uses distance (not weight), and you only have weight information. What you should probably do instead is find local maxima. Sep 19, 2017 at 18:49
• Scalability is also a pretty bad reason to like an algorithm. Random partitions scale even better. Sep 19, 2017 at 18:49
• Hi @Anony-Mousse, thank you again for the feedback. Agreed on the scalability aspect. It worked well for us but also gave good results. Could you recommend an algorithim that would be useful for my use case using weights for lat-lon. Sep 27, 2017 at 17:27