0

I’m trying to split a line vector (with buffer, although that could come after I split it) into many different components each 500 meters long to use for analysis.

Is there an easy way to do this so I dont have to do it by hand?

3

ee.Geometry.cutLines can do this, but with some extra steps:

  • It takes a list of cut distances, so you'll need to construct that; luckily ee.List.sequence is just the thing.
  • Since it returns a single MultiLineString geometry, you'll need to do .geometries() after to split it up.
var lines = ee.FeatureCollection(
  lineString.cutLines(ee.List.sequence(0, lineString.length(), 500))
    .geometries()
    .map(function (geometry) { return ee.Feature(ee.Geometry(geometry)); }));

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

Map.setCenter(-99.492, 44.73588, 15);
Map.addLayer(buffered);

enter image description here https://code.earthengine.google.com/745be17ffd62733024bcec9392be28ab

2
  • Thank you so much! One question: for my research, it is important that we dont oversample the data. Does the buffer at the end of each line segment overlap witht he one before it? Or does the buffer only extend out perpendicular to the line segment? – John Perrotti Oct 3 '20 at 22:07
  • 2
    @JohnPerrotti That's mostly a separate task, and I see you already posted a separate question, which is better than comments because it's more visible. Make sure to edit that question to embed rather than only link to code. Or, you could leave out the code.earthengine.google.com link and just link to this answer. The GIS SE site rules require all content for a question to be hosted on the site so it's permanently accessible to the public. – Kevin Reid Oct 4 '20 at 0:27

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.