公告:凡是在
2025 年 4 月 15 日前註冊使用 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 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
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
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間: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"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],[]]