gpt4 book ai didi

javascript - 在 Earth Engine Javascript API 中按 ID 加入两个要素集合

转载 作者:行者123 更新时间:2023-11-30 14:48:19 25 4
gpt4 key购买 nike

我只是想以这种方式加入两个集合,加入的特征集合具有主要和次要特征集合的所有属性。

// 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, {bar: 1, ID: 'a'}),
ee.Feature(null, {bar: 1, ID: 'b'}),
ee.Feature(null, {bar: 2, ID: 'c'}),
ee.Feature(null, {bar: 3, ID: 'd'}),
]);

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

// Define the join.
var innerJoin = ee.Join.simple()

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


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

最终的 toyJoin 特征集合应该有 5 个特征和 3 个属性 ID、foo 和 bar。非常感谢!

最佳答案

我不希望输出中有 5 个特征,因为您只有四个唯一 ID,并且输入集合中的 ID 之间是 1:1 的关系。无论如何,要获得内部联接,请使用 ee.Join.inner()。要合并结果,映射内部连接:

// 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, {bar: 1, ID: 'a'}),
ee.Feature(null, {bar: 1, ID: 'b'}),
ee.Feature(null, {bar: 2, ID: 'c'}),
ee.Feature(null, {bar: 3, ID: 'd'}),
]);

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

// Define the join.
var innerJoin = ee.Join.inner();

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

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

print(toyJoin.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
}));

关于javascript - 在 Earth Engine Javascript API 中按 ID 加入两个要素集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48562815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com