[GIS] Looping ImageCollection and FeatureCollection together in Google Earth Engine

googlegoogle-earth-enginesentinel-1

I am looking for a way to filter images for certain dates per feature in the feature collection. I want a function that would take each individual feature from the feature collection and then check from the image collection if there is an S1 image available for that region for a particular date. The dates are also listed in a column in the feature collection for each feature. So for feature1 is there an image for 2016-04-17 in the S1 collection, if yes select that feature. The feature collection table contains a column called 'SrcImgDate'. So I just want to filter out a feature collection with features that have an image for the srcimgdate next to them.

Expected output: FeatureCollection with all features that intersect with an image at the given srcimgdate and location

This is the imageCollection with a general date range

var Sentinel1 = S1.filter(ee.Filter.eq('transmitterReceiverPolarisation', pol))
                  .filterMetadata('instrumentMode', 'equals', 'IW')
                  .filterDate('2016-04-01','2016-08-30' )
                  .select(['VH','VV'])
                  .filterMetadata('resolution_meters', 'equals' , 10);

Here is the link to the FeatureCollection. You can limit it to 1000, as it has 11000 feature and would give an error to use such a large dataset.
https://code.earthengine.google.com/?asset=users/rawailnaeem/CA

Best Answer

In this approach I am not selecting VH and VV bands because some images in the collection don't have them (or one of them). Also, I am not filtering by transmitterReceiverPolarisation because the question does not provide one.

var table = ee.FeatureCollection("users/rawailnaeem/CA");
var S1 = ee.ImageCollection("COPERNICUS/S1_GRD");

var t = table.limit(1000);

var Sentinel1 = S1.filterMetadata('instrumentMode', 'equals', 'IW')
                  .filterDate('2016-04-01','2016-08-30' )
                  .filterMetadata('resolution_meters', 'equals' , 10)
                  .filterBounds(t);

var S1dates = Sentinel1.toList(Sentinel1.size()).map(function(img){
  var idate = ee.Image(img).date();
  return ee.Date.fromYMD(
    idate.get('year'),
    idate.get('month'),
    idate.get('day')
  ).millis()
});

// print images dates
print(S1dates.map(function(millis) {
  return ee.Date(millis).format();
}));

var newfc = ee.List(t.iterate(function(feat, ini){
  // cast
  var ini = ee.List(ini);
  var feat = ee.Feature(feat);

  // get src date
  var srcd = ee.String(feat.get('SrcImgDate'));
  var year = ee.Number.parse(srcd.slice(0, 4));
  var month = ee.Number.parse(srcd.slice(4, 6));
  var day = ee.Number.parse(srcd.slice(6, 8));

  var date = ee.Date.fromYMD(year, month, day).millis();

  var condition = S1dates.contains(date);

  return ee.Algorithms.If(condition, ini.add(feat), ini);
}, ee.List([])));

var newfc = ee.FeatureCollection(newfc);

print(newfc);