I have two feature collections and I want to change the features' property in one collection based on the other one where there is overlapping, but it seems that I just merge and keep both features where they overlap.

var Fcorrectioend=function(feature){
                    var day=ee.Number.parse((ee.String(feature.get('event_date'))).slice(8))
                    var Month=ee.Number.parse((ee.String(feature.get('event_date'))).slice(5,7))
                    var Year=ee.Number.parse((ee.String(feature.get('event_date'))).slice(0,4))
                    var date=ee.Date.fromYMD(Year,Month,day)
                            return feature.set('system:time_start',date)
var test=table.map(Fcorrectioend) 

var day1=test.filterDate('2020-01-01','2020-01-02')

var test=(day1.merge(Grid)).select('event_count')

Here is the link to the code: https://code.earthengine.google.com/7378c612af5339f972f6fc0b0e9ad85c


Here's a couple ways to do it; I'm not sure which one would be best for large collections. Probably the second one, but I haven't tested their performance.

We can, for each feature, look for an intersecting feature:

var all = collection1.map(function (feature) {
  return feature.set('intersects', 
      // Match features in collection2 that intersect this feature of collection1
      .filter(ee.Filter.intersects('.geo', feature.geometry()))
      // And test if there's at least one.

Or we could use joins to find both matches and non-matches, then combine them:

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

var matches = ee.Join.simple().apply(collection1, collection2, intersectsFilter)
  .map(function (feature) {
    return feature.set('intersects', true);
var nonMatches = ee.Join.inverted().apply(collection1, collection2, intersectsFilter)
  .map(function (feature) {
    return feature.set('intersects', false);

var all = matches.merge(nonMatches);

Demo: https://code.earthengine.google.com/057d12519093db2fa61503570fe912d9

  • Thank you, Kevin! Both did a beautiful job, though I used the second one as the main function. – pegah hashemvand Oct 31 '20 at 0:34

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.