1

I need to append two (slightly different) featureCollections that have no features in common: one collection describes polygons of one type, the other a different type with no spatial overlap and I intend to create a single featureCollection to use them to classify an image.

I think the solution might be a saveAll join, but I can't work out how it works (and I might be wrong!)


// Create the primary collection.
var primaryFeatures = ee.FeatureCollection([
  ee.Feature(null, {foo: 0, ID: 'a'}),
  ee.Feature(null, {foo: 1, ID: 'b'}),
  ee.Feature(null, {foo: 1, ID: 'c'}),
  ee.Feature(null, {foo: 2, ID: 'd'}),
]);

// Create the secondary collection.
var secondaryFeatures = ee.FeatureCollection([
  ee.Feature(null, {foo: 1, bar: 1, ID: 'e'}),
  ee.Feature(null, {foo: 3, bar: 1, ID: 'f'}),
  ee.Feature(null, {foo: 2, bar: 2, ID: 'g'}),
  ee.Feature(null, {foo: 2, bar: 3, ID: 'h'}),
]);

// Use an equals filter to specify how the collections match.
var toyFilter = ee.Filter.notEquals({
  leftField: 'ID',
  rightField: 'ID'
});

// Define the join.
var allJoin = ee.Join.saveAll({ matchesKey: 'ID'});

// Apply the join.
var toyJoin = allJoin.apply(primaryFeatures, secondaryFeatures,  toyFilter);

// Print the result.
print('All join toy example:', toyJoin);

I expect a featureCollection with 8 rows and (probably) three columns, but I don't mind if it drops the non-matching columns. I currently get a feature collection with just the secondary features (I think) and the ID in a very strange list format I don't understand.

CMB
  • 35
  • 5

1 Answers1

1
print(primaryFeatures.merge(secondaryFeatures));

This produces FeatureCollection (8 elements, 3 columns), with both of the inputs and none of the features altered in any way.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108