8

I would like to do 50 buffers from a known point. I know to do one by one, but I would like to do in a Loop. Is there any way to do it?

This is part of my code:

var buff1 = ee.Geometry.Point([-46.633286, -23.550510]).buffer(1000);

var buff...n= ee.Geometry.Point([-46.633286, -23.550510]).buffer(...n);

var buff50= ee.Geometry.Point([-46.633286, -23.550510]).buffer(50000);

var interval = 1000;

var outline = ee.Image().byte().paint({
  featureCollection: [buff1, buff...n, buff50],
  color: 1,
  width: 1
});

Map.addLayer(outline, {palette: ['red']}, 'buff1');
1

1 Answer 1

10

You don't need the loop. You can generate a distance list and use map function on it.

var point = ee.Geometry.Point([-46.633286, -23.550510]);

// generate a buffer distance list
var distance_list = ee.List.sequence({start:1000, end:50000, step:1000});

var buffer_func = function (distance) {
    // new feature containing the buffer
    return ee.Feature(point.buffer(distance), {});
}

var buffers = ee.FeatureCollection(distance_list.map(buffer_func));

var outline = ee.Image().byte().paint({
  featureCollection: buffers,
  color: 1,
  width: 1
});

Map.addLayer(outline, {palette: ['red']}, 'buff1');

enter image description here

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.