2

I am creating a code to automate the process of downloading point-based reflectance data tables that comes from a JSON file. The code is almost ready and I can reduce and export a table containing the reflectance data per band at each point. The problem is that I'm generating a table with all the reflectance values ​​for each point I've created for all available dates in the time interval between points. I need to generate a table with only data referring to the date the point was created.

Any idea how to do this?

This is the code working so far: Code here

var ict = ee.Dictionary({RAWJSONDATA})
var feats = ee.FeatureCollection(ee.List(dict.get('pings')).map(function(feat){
  feat = ee.Dictionary(feat);
  var geom = ee.Geometry.Point([ee.Number.parse(feat.get('longitude')), ee.Number.parse(feat.get('latitude'))]);
  var getDate = ee.String(feat.get('datetime'));
  var systemDate = ee.Date.parse("dd MMM YYYY hh:mm:ss aa", getDate).millis();
  return ee.Feature(geom, ee.Dictionary(feat)).set('system:time_start', systemDate);
}));
feats = ee.FeatureCollection(feats.setMulti(dict));

print(feats);

var rrs = ee.ImageCollection("NASA/OCEANDATA/MODIS-Aqua/L3SMI")
    .filterDate('2018-2-22','2018-2-24') //HOW DO I FILTER WITH THE "systemDate" ??

    .select('Rrs_488', 'Rrs_531', 'Rrs_547', 'Rrs_555');

var reduceR = function(image) {
  var reducedVal = image.reduceRegions({
    collection: feats,
    reducer: ee.Reducer.first(),
  });
  return reducedVal;
};

var mRrs = rrs.map(reduceR);
mRrs = ee.FeatureCollection(mRrs).flatten();

Export.table.toDrive({
   collection: mRrs, 
   description: 'aaaagoraaa', 
   fileNamePrefix: 'vaiii', 
   fileFormat: 'CSV', 
   selectors: ('Rrs_488', 'Rrs_531', 'Rrs_547', 'Rrs_555'),
 });
0

1 Answer 1

0

For this purpose, you should map over all your data points (which contain a date value) instead of mapping over the image collection.

I show you an example where for every point, the date is evaluated and a date range of a specified number of days ("dayRange") is made around that date. Then we filter the image collection on that dateRange and calculate a mean image of it. We will then sample the statisticts a that point using reduceRegion().

// set a day range
var dayRange = 30; // == range of days around each sample points 

// select the image data from NASA
var rrs = ee.ImageCollection("NASA/OCEANDATA/MODIS-Aqua/L3SMI")
    .select(['Rrs_488', 'Rrs_531', 'Rrs_547', 'Rrs_555']);

// map over the features, filter the collection for the date of every point and get the point data
var feats = feats.map(function(feat){
  feat = ee.Feature(feat);
  var date = ee.Date(feat.get('system:time_start'));
  var dateRange = ee.DateRange(date.advance(-(dayRange/2), 'day'), date.advance(dayRange/2, 'day'));
  var image = rrs.filterDate(dateRange).mean();
  var data = image.reduceRegion(ee.Reducer.first(), feat.geometry(), 500);
  return ee.Feature(feat.setMulti(data))
});

// print the features to the console
print(feats)

Inspecting the output, you will see that even with a daterange of 30 days, you still won't have valid data at every point. You should either be statisfied with that, increase the date range or, make a buffer around the point (using "feat.geometry().buffer(BUFFER_RADIUS_IN_METERS)" ) to increase the spatial extent around each sample point.

link code

1
  • Perfect !! I really appreciate your help !!
    – user142308
    Commented May 7, 2019 at 14:09

Your Answer

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