如何附加两个 featureCollections?

How can I append two featureCollections?

我需要附加两个(略有不同)featureCollections,它们没有共同的特征:一个集合描述了一种类型的多边形,另一个描述了没有空间重叠的不同类型,我打算创建一个featureCollection 使用它们对图像进行分类。

我认为解决方案可能是 saveAll 连接,但我不知道它是如何工作的(我可能错了!)


// 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);

我希望 featureCollection 有 8 行和(可能)三列,但我不介意它是否删除不匹配的列。我目前得到的特征集合只有次要特征(我认为)和我不理解的非常奇怪的列表格式的 ID。

print(primaryFeatures.merge(secondaryFeatures));

这会产生 FeatureCollection (8 elements, 3 columns),其中输入和 none 特征都以任何方式改变。