# Divide a list of points into clusters based on the gap between them

I would like to know how I can divide the attached list of points to as many clusters as possible based on the gap between the patches. Then I can decide which one should be kept and which remove. I tried different options in Findclusters command but none of them gave me a correct answer. Any help is really appreciated.

https://pastebin.com/WMC4GhxE

This gets you four clusters with points grouped together in ccmp. The two large islands are depicted in orange and blue, the small long island in green, and a tiny island in red.

nng = NearestNeighborGraph[data, 8];
ccmp = ConnectedComponents[nng];
ListPointPlot3D[ccmp]

(* Length@ccmp == 4 *)


• Thank you! It worked! However, when I changed the value of the coefficient in the bracket of the NeasrestNeighborGraph from 8 to 4, the number of patches changed to 5 and showed me another small island as a separate cluster which is correct basically. Is there any criterion to select the value of the coefficient? For example, the value of 1 gave me 30 patches. I am asking as I need to apply the script on different data and need to use a constant coefficient. – Mehdi Ebadi Jun 13 '20 at 17:27
• I just chose 8 randomly. If instead you put a list {k,r} it uses the k nearest within distance r, and {All,r} connects all elements within distance r – flinty Jun 13 '20 at 17:31
• Thank you for the response! By distance, you mean Euclideandistance? – Mehdi Ebadi Jun 13 '20 at 17:38
• Yes by default, but it also takes an option DistanceFunction, e.g , DistanceFunction -> ManhattanDistance – flinty Jun 13 '20 at 17:43
• Another question and appreciate your response. Is always the output from the largest list (with the most number of members) to the smallest one? – Mehdi Ebadi Jun 13 '20 at 18:29