# Create feature collection of polygons' centroids in GEE

I am trying to determine the distance between province centroids and a polygon. Based on this past post, I was able to store the geographic coordinates of the province centroids into their feature collection.

``````
var Iraq = ee.FeatureCollection('users/salem043/Iraq_ADM1');  //available to all users
var getCentroids = function(feature) {
return feature.set({centralPoint: feature.centroid()});
};

var IraqCentroids = Iraq.map(getCentroids);

``````

The new feature collection still recognizes the original feature collection's geography. Consequently, my spatial filter using IraqCentroids still identifies the minimum distance between the province's border and the polygon, not the distance between the province's centroid and the polygon.

Is there a way that I can create a new feature collection of points with the geographies of the province centroids, based on the properties stored in IraqCentroids?

Alternatively, is there a way to adjust my minimum distance algorithm such that it is measuring the smallest distance between the centroids stored as properties in IraqCentroids, not every geographic point that constitutes the province polygons? The minimum distance algorithm is below:

``````
var spatialFilter = ee.Filter.withinDistance({
distance: 5000000000000,  //Make it big, we need to link Basra etc. to border
leftField: '.geo',
rightField: '.geo',
maxError: 10
});

var joined = ee.Join.saveAll({
matchesKey: 'neighbors',
measureKey: 'distance',
ordering: 'distance'
}).apply({
primary: IraqCentroids,
secondary: sharedBorder, //data not shared
condition: spatialFilter
});

var withNearestDist = joined.map(function(f) {
var nearestDist = ee.Feature(ee.List(f.get('neighbors')).get(0))
.get('distance');
return f.set('nearestDist', nearestDist);
});
``````

I figured it out. A mapping function can extract this information and place it in a separate dataframe

``````
var getCentroids = function(feature) {
return feature.set({centralPoint: feature.centroid()});
};

var IraqCentroids = Iraq.map(getCentroids);
print("Central nodes", IraqCentroids);

var IraqCentroids2 = IraqCentroids.map(function(f) {
var centroid = ee.Feature(ee.List(f.get('centralPoint')));
return centroid;
});
``````