2

I am trying to generate multiple buffers around a layer that represents cities (FeatureCollection). Use the following code to create the buffers: // Function to create buffers of different sizes in Google Earth Engine . The problem is that this code generates polygons that include the inside area. I need to generate buffers on the outside, like doughnuts or perimeter rings.

I tried to use .difference to remove the original polygons from the buffers but I get the error "....difference is not a function"

Can anyone help me?

var geometry = 
    /* color: #d63000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      },
      {
        "type": "rectangle"
      },
      {
        "type": "rectangle"
      }
    ] */
    ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Polygon(
                [[[-92.93044076036253, 43.38666530027385],
                  [-92.93044076036253, 43.371630789523294],
                  [-92.90812478135862, 43.371630789523294],
                  [-92.90812478135862, 43.38666530027385]]], null, false),
            {
              "system:index": "0"
            }),
        ee.Feature(
            ee.Geometry.Polygon(
                [[[-93.016614771593, 43.389328699363205],
                  [-93.016614771593, 43.36986507859759],
                  [-92.99155221055784, 43.36986507859759],
                  [-92.99155221055784, 43.389328699363205]]], null, false),
            {
              "system:index": "1"
            }),
        ee.Feature(
            ee.Geometry.Polygon(
                [[[-93.09137330125608, 43.39935439198635],
                  [-93.09137330125608, 43.38213974024519],
                  [-93.06734070848265, 43.38213974024519],
                  [-93.06734070848265, 43.39935439198635]]], null, false),
            {
              "system:index": "2"
            })]);

var RingBuffer = function (Poligono, DistBuff) {
  
var BufferFeature = function(f) {
  f = ee.Feature(f);
  var buffer_size = f.get('buffer_size');
  return f.buffer(buffer_size);   
};

var BufferFeaturesByDistance = function (fc, buffer_size) {

var SetBufferSize = function(f) {
    return f.set({'buffer_size': buffer_size});
  };

return (Poligono).map(SetBufferSize).map(BufferFeature);
};

var Buffer = BufferFeaturesByDistance(Poligono, DistBuff)

return (Buffer).difference(Poligono)
};

var Buff1 = RingBuffer (geometry, 2000);

Map.addLayer(Buff1);
1
  • 1
    Could you edit your question to show a complete, simple, runnable example where you tried to use .difference() and it didn't work? difference should work for this purpose, and showing your code will let us figure out how to fix it for you.
    – Kevin Reid
    Commented Sep 3, 2020 at 20:05

1 Answer 1

1

Here is a simple example on how to do a donut buffer:

var point = ee.Geometry.Point(-90.1751, 18.5854)
var donut = point.buffer(5000).difference(point.buffer(3000))

Map.centerObject(point, 12)
Map.addLayer(point)
Map.addLayer(donut)

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.