I am trying to cluster points inside the USA for which I have the latitude and the longitude. My condition is that, every point within a cluster should be less than 25 miles away from every other point inside that cluster. I have tried to do this using agglomerative clustering and have implemented this in Python. But the problem is that since agglomerative clustering uses a distance matrix, it becomes excessively time consuming for large number of points. I try to cluster close to 10000-15000 points at once. What method can I use to do this using agglomerative clustering or any other method in Python or preferably using SQL like PostGIS.


Vast question, a matrix distance is really not the way to go for a lot of points. If you want to do it yourself, look into quadtree and nearest neighbourg. The classicals algorithms used for clustering would be DBScan or Kmeans, but for your exemple you can simply use Postgis and the function ST_ClusterWithin (and you can test ST_ClusterDBSCAN and ST_ClusterKMeans in Postgis too if you want to try these, they are more elaborate but they do not answer exactly your problem).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.