公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。如果您在 2025 年 9 月 26 日之前未完成验证,您的访问权限可能会被暂停。
ee.FeatureCollection.merge
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将两个集合合并为一个。结果包含任一集合中的所有元素。
第一个集合中的元素的 ID 将以“1”为前缀,第二个集合中的元素的 ID 将以“2”为前缀。
用法 | 返回 |
---|
FeatureCollection.merge(collection2) | FeatureCollection |
参数 | 类型 | 详细信息 |
---|
此:collection1 | FeatureCollection | 要合并的第一个集合。 |
collection2 | FeatureCollection | 要合并的第二个集合。 |
示例
代码编辑器 (JavaScript)
// FeatureCollection of points representing forest cover.
var fcForest = ee.FeatureCollection([
ee.Feature(ee.Geometry.Point([-122.248, 37.238]),
{'id': 0, 'cover_class': 'forest'}),
ee.Feature(ee.Geometry.Point([-122.204, 37.222]),
{'id': 1, 'cover_class': 'forest'}),
ee.Feature(ee.Geometry.Point([-122.110, 37.199]),
{'id': 2, 'cover_class': 'forest'})
]);
// FeatureCollection of points representing urban cover.
var fcUrban = ee.FeatureCollection([
ee.Feature(ee.Geometry.Point([-121.953, 37.372]),
{'id': 0, 'cover_class': 'urban'}),
ee.Feature(ee.Geometry.Point([-121.861, 37.308]),
{'id': 1, 'cover_class': 'urban'}),
ee.Feature(ee.Geometry.Point([-121.984, 37.372]),
{'id': 2, 'cover_class': 'urban'})
]);
// Merge the two FeatureCollections into one.
var fcMerged = fcForest.merge(fcUrban);
// Display FeatureCollections on the map.
Map.setCenter(-122.034, 37.296, 11);
Map.addLayer(fcForest, {color: 'green'}, 'Forest points');
Map.addLayer(fcUrban, {color: 'grey'}, 'Urban points');
Map.addLayer(fcMerged, {color: 'yellow'}, 'Protected areas merged');
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# FeatureCollection of points representing forest cover.
fc_forest = ee.FeatureCollection([
ee.Feature(
ee.Geometry.Point([-122.248, 37.238]),
{
'id': 0,
'cover_class': 'forest',
'id': 0,
'cover_class': 'forest',
},
),
ee.Feature(
ee.Geometry.Point([-122.204, 37.222]),
{
'id': 1,
'cover_class': 'forest',
'id': 1,
'cover_class': 'forest',
},
),
ee.Feature(
ee.Geometry.Point([-122.110, 37.199]),
{
'id': 2,
'cover_class': 'forest',
'id': 2,
'cover_class': 'forest',
},
),
])
# FeatureCollection of points representing urban cover.
fc_urban = ee.FeatureCollection([
ee.Feature(
ee.Geometry.Point([-121.953, 37.372]),
{'id': 0, 'cover_class': 'urban', 'id': 0, 'cover_class': 'urban'},
),
ee.Feature(
ee.Geometry.Point([-121.861, 37.308]),
{'id': 1, 'cover_class': 'urban', 'id': 1, 'cover_class': 'urban'},
),
ee.Feature(
ee.Geometry.Point([-121.984, 37.372]),
{'id': 2, 'cover_class': 'urban', 'id': 2, 'cover_class': 'urban'},
),
])
# Merge the two FeatureCollections into one.
fc_merged = fc_forest.merge(fc_urban)
# Display FeatureCollections on the map.
m = geemap.Map()
m.set_center(-122.034, 37.296, 11)
m.add_layer(fc_forest, {'color': 'green'}, 'Forest points')
m.add_layer(fc_urban, {'color': 'grey'}, 'Urban points')
m.add_layer(fc_merged, {'color': 'yellow'}, 'Protected areas merged')
m
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-26。"],[],[]]