-1

I have a reservoir and its buffer (see below). I want to do the difference between the 2 so that my buffer is just a contour around the polygon. I tried the 2 following scripts but cannot get the "contour buffer" to appear. I also tried with symmetricDifference, but same errors.

First:

var buffercontour = reservoir.difference(reservoirbuffer, ee.ErrorMargin(1));
Map.addLayer(buffercontour, {}, 'buffercontour');

Error message:
reservoir.difference is not a function
    in <global>, line 118
    in <global>, line 176

Then:

var reservoirbufferPolygon = ee.Geometry.Polygon(reservoirbuffer);
var reservoirPolygon = ee.Geometry.Polygon(reservoir);

var buffercontour = reservoirPolygon.difference(reservoirbufferPolygon, ee.ErrorMargin(1));
Map.addLayer(buffercontour, {c}, 'buffercontour');

Error message:
buffercontour: Layer error: GeometryConstructors.Polygon, argument 'coordinates': Invalid type. Expected: List<Object>. Actual: FeatureCollection.

Any ideas?

enter image description here

1

Here is a simple script that demonstrates how to take the difference of two ee.Geometry.Polygon() objects, using ee.Polygon.Geometry.difference():

var poly_inner = ee.Geometry.Polygon(
        [[[-119.14, 38.01],
          [-119.07, 37.95],
          [-118.91, 38.00],
          [-119.01, 38.06]]]);

var poly_outer = ee.Geometry.Polygon(
         [[[-119.17, 38.00],
           [-119.09, 37.93],
           [-118.93, 37.96],
           [-118.86, 38.01],
           [-118.96, 38.06],
           [-119.05, 38.07],
           [-119.15, 38.02]]]);

var poly_diff = poly_outer.difference(poly_inner);

Map.centerObject(poly_outer);
Map.addLayer(poly_inner, {color:'red'}, 'poly_inner (red)', false);
Map.addLayer(poly_outer, {color:'blue'}, 'poly_outer (blue)', false);
Map.addLayer(poly_diff, {color:'green'}, 'poly_diff (green)');

Screenshot showing polygon difference

0

I tried ErrorMargin in the same way as you did and it worked.

In your first example, I think you commited an error in line where you wrote reservoir.difference. Better, try to do this example in other code editor to avoid writing wrongs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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