1

I am working to extract surface reflectance from the image collection, and I have only line geometry representing the central line of the river. I would like to convert the line into points and each point should be 500m in GEE. Then I will be able to extract the pixel value based on the computed points.

1 Answer 1

2

The function below should work if you input a lineFeature and define the count (e.g. amount of points to achieve a 500m spacing).

function lineToPoints(lineString, count) {
  var length = lineString.length();
  var step = lineString.length().divide(count);
  var distances = ee.List.sequence(0, length, step)

  function makePointFeature(coord, offset) {
    var pt = ee.Algorithms.GeometryConstructors.Point(coord);
    var coords = pt.coordinates(); // set coords as feature property
    
    return new ee.Feature(pt).set({'offset': offset,
                                  'lat': coords.get(0),
                                  'lon': coords.get(1)
    })
  }
  
  var lines = lineString.cutLines(distances).geometries();

  var points = lines.zip(distances).map(function(s) {
    var line = ee.List(s).get(0);
    var offset = ee.List(s).get(1)
    return makePointFeature(ee.Geometry(line).coordinates().get(0), offset)
  })
  
  points = points.add(makePointFeature(lineString.coordinates().get(-1), length))

  return new ee.FeatureCollection(points);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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