簡單彙整

簡單彙整會根據篩選器中的比對條件,傳回 primary 集合中與 secondary 集合中任一元素相符的元素。如要執行簡單的彙整作業,請使用 ee.Join.simple()。這項功能可能有助於找出不同集合中的共同元素,或篩選某個集合。舉例來說,假設有兩個圖片集合 (可能) 含有部分相符的元素,其中「相符」是根據篩選器中指定的條件定義。舉例來說,相符表示圖片 ID 相同。由於兩個集合中的相符圖片相同,請使用簡單的彙整作業來找出這組相符圖片:

程式碼編輯器 (JavaScript)

// Load a Landsat 8 image collection at a point of interest.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filterBounds(ee.Geometry.Point(-122.09, 37.42));

// Define start and end dates with which to filter the collections.
var april = '2014-04-01';
var may = '2014-05-01';
var june = '2014-06-01';
var july = '2014-07-01';

// The primary collection is Landsat images from April to June.
var primary = collection.filterDate(april, june);

// The secondary collection is Landsat images from May to July.
var secondary = collection.filterDate(may, july);

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

// Create the join.
var simpleJoin = ee.Join.simple();

// Apply the join.
var simpleJoined = simpleJoin.apply(primary, secondary, filter);

// Display the result.
print('Simple join: ', simpleJoined);

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

# Load a Landsat 8 image collection at a point of interest.
collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA').filterBounds(
    ee.Geometry.Point(-122.09, 37.42)
)

# Define start and end dates with which to filter the collections.
april = '2014-04-01'
may = '2014-05-01'
june = '2014-06-01'
july = '2014-07-01'

# The primary collection is Landsat images from April to June.
primary = collection.filterDate(april, june)

# The secondary collection is Landsat images from May to July.
secondary = collection.filterDate(may, july)

# Use an equals filter to define how the collections match.
filter = ee.Filter.equals(leftField='system:index', rightField='system:index')

# Create the join.
simple_join = ee.Join.simple()

# Apply the join.
simple_joined = simple_join.apply(primary, secondary, filter)

# Display the result.
display('Simple join:', simple_joined)

在前述範例中,您會發現要彙整的資料集在時間上重疊約一個月。請注意,套用此彙整時,輸出內容會是 ImageCollection,其中只包含 primary 集合中的相符圖片。輸出內容應如下所示:

Image LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140505 (17 bands)
Image LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140521 (17 bands)

這項輸出內容顯示 primarysecondary 集合 (5 月 5 日和 5 月 21 日的圖片) 之間有兩張圖片相符 (如篩選器所指定)。