Skip to main content
2 of 2
comment code
Rodrigo E. Principe
  • 10.2k
  • 1
  • 31
  • 37

I have no access to your fusion table, so I made up one to make the answer.

First approach: 2D table

var yearly = ee.ImageCollection('JRC/GSW1_0/YearlyHistory');
// function to map over the FeatureCollection
var mapfunc = function(feat) {
  // get feature geometry
  var geom = feat.geometry()
  // function to iterate over the yearly ImageCollection
  // the initial object for the iteration is the feature
  var addProp = function(img, f) {
    // cast Feature
    var newf = ee.Feature(f)
    // get date as string
    var date = img.date().format()
    // extract the value (first) of 'waterClass' in the feature
    var value = img.reduceRegion(ee.Reducer.first(), geom, 30).get('waterClass')
    // if the value is not null, set the values as a property of the feature. The name of the property will be the date
    return ee.Feature(ee.Algorithms.If(value,
                                       newf.set(date, ee.String(value)),
                                       newf.set(date, ee.String('No data'))))
  }
  var newfeat = ee.Feature(yearly.iterate(addProp, feat))
  return newfeat
};

var newft = fg_points.map(mapfunc);

// Export
Export.table.toDrive(newft,
"export_Points",
"export_Points",
"export_Points");

Second approach: 1D table

var yearly = ee.ImageCollection('JRC/GSW1_0/YearlyHistory');
// function to map over the FeatureCollection
var mapfunc = function(feat) {
  // get feature id
  var id = ee.String(feat.id())
  // get feature geometry
  var geom = feat.geometry()
  // make an empty list to store the features
  var newfc = ee.List([])
  // function to iterate over the ImageCollection
  var addProp = function(img, fc) {
    // the initial value is the empty list
    fc = ee.List(fc)
    // get the date as string
    var date = img.date().format()
    // extract the value of 'waterClass'
    var value = img.reduceRegion(ee.Reducer.first(), geom, 30).get('waterClass')
    // If the value is null then store it as 'No data'
    var val = ee.String(ee.Algorithms.If(value, ee.String(value), ee.String('No data')))
    // make the name of the feature (feat_id-date)
    var featname = ee.String("feat_").cat(id).cat(ee.String("-")).cat(date)
    // make the Feature
    var newfeat = ee.Feature(geom, {name:featname,
                                    value:val})
    // add the value to the list
    return fc.add(newfeat)
  }
  var newfeat = ee.FeatureCollection(ee.List(yearly.iterate(addProp, newfc)))
  return newfeat
};

var newft = fg_points.map(mapfunc).flatten();

Export.table.toDrive(newft,
"export_Points",
"export_Points",
"export_Points");

If features in your FeatureCollection have a name property (or something that identifies each feat) you can change in the second approach:

var id = ee.String(feat.id())

for

var id = ee.String(feat.get('name'))
Rodrigo E. Principe
  • 10.2k
  • 1
  • 31
  • 37