I have a list of points P=[p1,...pN] where pi=(latitudeI,longitudeI).
Using Python 3, I would like to find a smallest set of clusters (disjoint subsets of P) such th
Here is a solution that seems correct and will behave O(N^2) worst case and better depending on the data:
def my_cluster(S,distance):
coords=set(S)
C=[]
while len(coords):
locus=coords.pop()
cluster = [x for x in coords if vincenty(locus,x).km <= distance]
C.append(cluster+[locus])
for x in cluster:
coords.remove(x)
return C
NOTE: I am not marking this as an answer because one of my requirements is that it be a smallest set of clusters. My first pass is good but I haven't proven that it is a smallest set.
The result (on a larger set of points) can be visualized as follows: