I have a dataset with many polygons that come from a fusion table ('xxxxx'):

var polygons = ee.FeatureCollection('xxxxx');

I want to compute the centroid and a buffer of Z meters for each of these polygons. How do I do that?

1 Answer 1


The task you are asking to do is termed mapping over a FeatureCollection in Google Earth Engine. You can see GEE documentation on doing so here.

To compute the tasks you want, you can write small functions that append the centroid coordinates for each feature as an attribute, or return a FeatureCollection with the specified buffer:

var polygons = ee.FeatureCollection('xxxxx');

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

var bufferPoly = function(feature) {
  return feature.buffer(Z);   // substitute in your value of Z here

var fcWithCentroids = polygons.map(getCentroids);
print(fcWithCentroids) // access the features and look at the properties, for which there should be a point with the centroid coords

var bufferedPolys = polygons.map(bufferPoly);
Map.addLayer(bufferedPolys, {}, 'Buffered polygons');
Map.addLayer(polygons, {}, 'Unbuffered polygons'); // for comparison

There may be more elegant ways of getting the map function to return both tasks with a single go, but I'll let you explore how to do that as it will be a good learning experience!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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