2

I am using an aerosol index, which I reduced to a daily mean for 2019:


var airq_19 = ee.ImageCollection('COPERNICUS/S5P/NRTI/L3_AER_AI')
  .select('absorbing_aerosol_index')
  .filterDate('2019-01-01', '2019-12-31');

var days = ee.List.sequence(1, 365);

var composites = ee.ImageCollection.fromImages(days.map(function(d) {
  var filtered = airq_19.filter(ee.Filter.calendarRange({
    start: d,
    field: 'day_of_year'
  }));
  return filtered.mean().set('day', d);
}));

I also have point data that is dated:

var events = ee.FeatureCollection('users/salem043/ACLED16to20Iraq');

To obtain the mean values in the aerosol index, I would normally use a spatial join like this:

var spatialFilter = ee.Filter.intersects({
  leftField: '.geo',
  rightField: '.geo'
});

var joinAll = ee.Join.saveAll('matched').apply(events, airq_19, spatialFilter);

var outcomes = joinAll.map(function(feature){
  var joinedFeat =  ee.List(feature.get('matched'));
  var polygon = ee.Feature(ee.FeatureCollection(joinedFeat).first());
  return ee.Feature(feature.copyProperties(polygon, properties)).select(properties);
});

How do I adjust the functions above such that the joins match on the basis of geography AND date? Script is here

Feb. 9th update: I reformatted my imported feature collection so I could match days based on a number 1-365 for 2019.

var spatialFilter = ee.Filter.and(
  ee.Filter.intersects({
    leftField: '.geo',
    rightField: '.geo'
  }),
  ee.Filter.equals({
    leftField: 'day',
    rightField: 'day'
  })
);

Now the join recommended below produces a new dataframe, but I am missing one more step to produce the mean aerosol index information as a variable (it's saved as a band for each feature in the new feature collection). Updated code is here.

1

I'm not sure exactly how you want to combine these composites with your events, but in general, you can join on multiple properties by using ee.Filter.and():

var filter = ee.Filter.and(
  ee.Filter.intersects({
    leftField: '.geo',
    rightField: '.geo'
  }),
  ee.Filter.equals({
    leftField: 'date',
    rightField: 'date'
  })
)

Something like this could perhaps be an option too:

ee.Join.saveAll('matched')
  .apply({
    primary: events, 
    secondary: airq_19, 
    condition: ee.Filter.and(
      ee.Filter.intersects({
        leftField: '.geo',
        rightField: '.geo'
      }),
      ee.Filter.maxDifference({
        // Include airq within 24h of event
        difference: 24 * 3600 * 1000, 
        leftField: 'system:time_start',
        rightField: 'system:time_start'
      })
    )
  })

https://code.earthengine.google.com/1afa49f61a5f9d09327f1746a1d4c80e

|improve this answer|||||
  • Thanks! I used the first (Filter.and) and was able to obtain a feature collection, but where the aerosol values are still saved as bands for each feature (point). Any tips on how to reclassify the information as a property in this feature collection? A link to my updated code is above. – user157564 Feb 10 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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