# Clustering of Coordinates?

i want to detect wildfire in earth engine. So the classification works almost very well. But now i want to determine the fire polygons, calculate their centroids and then cluster centroids which are within a certain distance. Like, if point A is near to point B and B is near to Point C. Then these three point belongs to the same fire and i want to calculate a new centroid. So, at this point i have a list with several centroids of the polygons. From this list, i calculated a nested list where every index belongs to the same index in the centroid point list. Also every entry in the nested list, has an sublist with the points within distance. For example: Centroid Point List:

-> A,

 -> B,

 -> C,

 -> D

After calculating the within distance. The nested list is:

 (A) --> [->A;->B]

 (B) --> [->B;->A]

 (C) --> [->C;->B]

 (D) --> [->D]

Now i want to connect A,B,C and seperate D. But i absolutely dont know how.

Here's a snippet of my code:

```

```//Cluster centroids

// Define a spatial filter, with distance 100 m.

var distFilter = ee.Filter.withinDistance({

distance: 100,

leftField: '.geo',

rightField: '.geo',

maxError: 10
});

// Define a saveAll join.

var distSaveAll = ee.Join.saveAll({

matchesKey: 'points'

});

// Apply the join.

var spatialJoined = distSaveAll.apply(fireCentroid2Features, fireCentroid2Features, distFilter);

// Nested List
var test=ee.List(spatialJoined.toList(spatialJoined.size()));

print(test)
``````

fireCentroid2Features is a FeatureCollection containing the Centroids Coordinates. test is the nested List.