5

I need to create a feature collection from a list containing coordinates and band values. These are extracted from a landsat image as shown in this linked script.

Extract complete pixel values inside a geometry

I'm unable to find a solution in creating a feature collection. Here is the tail end code.

var valuesList = joinedImage.reduceRegion({
  reducer: ee.Reducer.toList(4),
  geometry: myGeometry
}).values().get(0);

var feature = ee.Feature(null, valuesList);


// Wrap the Feature in a FeatureCollection for export.
var myFeatures = ee.FeatureCollection([feature]);


// Export the image, specifying scale and region.
Export.table.toDrive(myFeatures,
"data",
"myData",
"B4-B5", 
"CSV");

This doesn't work, because it is clearly the wrong way to create the feature collection. I've tried to create it similar to Rodrigo E. Principe's solution of mapping a Feature Collection but I can't seem to create the initial feature collection to start with.

4
  • are you working in Argentina? Commented Apr 9, 2018 at 1:30
  • Any way to message privately? Commented Apr 9, 2018 at 12:53
  • yes, fitoprincipe82 at gmail =) Commented Apr 9, 2018 at 13:41
  • @RodrigoE.Principe can you please take a look at my question gis.stackexchange.com/questions/294595/… here. I am trying to do the exact same thing but with multiple geometries. It is really urgent if I can get some help on this. Thank you Commented Sep 3, 2018 at 17:38

1 Answer 1

6
valuesList = ee.List(valuesList) // Cast valuesList

var myFeatures = ee.FeatureCollection(valuesList.map(function(el){
  el = ee.List(el) // cast every element of the list
  var geom = ee.Geometry.Point([ee.Number(el.get(0)), ee.Number(el.get(1))])
  return ee.Feature(geom, {'B4':ee.Number(el.get(2)), 'B5':ee.Number(el.get(3))})
}))

Map.addLayer(myFeatures) // see the result
Map.centerObject(myFeatures)

// Export the image, specifying scale and region.
Export.table.toDrive(myFeatures,
"data",
"myData",
"B4-B5", 
"CSV");
1
  • Any clue how I could include a "date" column in the above code snippet?
    – csheth
    Commented Oct 8, 2018 at 9:06

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.