2

I have a line split up into line segments, with each segment having a buffer around that. I’m trying to remove where they overlap (basically where the darker circles are within the line buffer itself), so that when I later mask by buffer it doesn’t have duplicated results.

Anyone know how to remove those overlaps (and ideally keep the land they covered still within ONE buffered area)?

var lines = ee.FeatureCollection(
linetosplit.cutLines(ee.List.sequence(0, linetosplit.length(), 9000))
.geometries()
.map(function (geometry) { return ee.Feature(ee.Geometry(geometry)); 
}));

var buffered = lines.map(function (feature) {
return feature.buffer(2000);
 });


Map.addLayer(buffered);

print(buffered)

Link to code: https://code.earthengine.google.com/b6b989b9d0bed22a8882f95bd68d0d4d

1
  • I tried to run the .clip operation but I don’t think it will work since its within the same feature collection. Is there a way to select a layer within the feature collection, use it as the .clip by layer, and use it as a function to then select the next layer to repeat it again? Commented Oct 5, 2020 at 0:14

1 Answer 1

2

You can first extract the individual features from the feature collection and find the intersections between them using:

//extract individual features
var f0 = buffered.filter(ee.Filter.eq("system:index", '0'));
var f1 = buffered.filter(ee.Filter.eq("system:index", '1'));
var f2 = buffered.filter(ee.Filter.eq("system:index", '2'));
var f3 = buffered.filter(ee.Filter.eq("system:index", '3'));
var f4 = buffered.filter(ee.Filter.eq("system:index", '4'));
var f5 = buffered.filter(ee.Filter.eq("system:index", '5'));
//compute spatial intersections between features  
var int1 = f0.geometry().intersection(f1.geometry());
var int2 = f1.geometry().intersection(f2.geometry());
var int3 = f2.geometry().intersection(f3.geometry());
var int4 = f3.geometry().intersection(f4.geometry());
var int5 = f4.geometry().intersection(f5.geometry());

Then, you combine the intersections into a Multipolygon and compute the spatial difference using:

//combine intersections and plot
var intersections = ee.Geometry.MultiPolygon([int1, int2, int3, int4, int5]);
Map.addLayer(intersections, {color: 'FFFF00'}, 'intersections');
//compute difference and plot
var difference = buffered.geometry().difference(intersections)
Map.addLayer(difference, {color: '#24f8ff'}, 'difference');

FULL SCRIPT HERE

Results

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.