儲存彙整是一種在 Earth Engine 中表示一對多關係的方式。與內部聯結不同,儲存聯結會將 secondary
集合中的相符項目儲存為 primary
集合中地圖項目的命名屬性。如要儲存所有相符項目,請使用 ee.Join.saveAll()
。如果存在一對多關係,saveAll()
彙整會將所有相符的功能儲存為 ee.List
。primary
集合中的不相符元素會遭到捨棄。舉例來說,假設您需要在收藏集中每張 Landsat 圖像的兩天內,取得所有 MODIS 圖像。本範例會使用 saveAll()
彙整作業來達成這個目的:
程式碼編輯器 (JavaScript)
// Load a primary collection: Landsat imagery. var primary = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA') .filterDate('2014-04-01', '2014-06-01') .filterBounds(ee.Geometry.Point(-122.092, 37.42)); // Load a secondary collection: MODIS imagery. var modSecondary = ee.ImageCollection('MODIS/006/MOD09GA') .filterDate('2014-03-01', '2014-07-01'); // Define an allowable time difference: two days in milliseconds. var twoDaysMillis = 2 * 24 * 60 * 60 * 1000; // Create a time filter to define a match as overlapping timestamps. var timeFilter = ee.Filter.or( ee.Filter.maxDifference({ difference: twoDaysMillis, leftField: 'system:time_start', rightField: 'system:time_end' }), ee.Filter.maxDifference({ difference: twoDaysMillis, leftField: 'system:time_end', rightField: 'system:time_start' }) ); // Define the join. var saveAllJoin = ee.Join.saveAll({ matchesKey: 'terra', ordering: 'system:time_start', ascending: true }); // Apply the join. var landsatModis = saveAllJoin.apply(primary, modSecondary, timeFilter); // Display the result. print('Join.saveAll:', landsatModis);
import ee import geemap.core as geemap
Colab (Python)
# Load a primary collection: Landsat imagery. primary = ( ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA') .filterDate('2014-04-01', '2014-06-01') .filterBounds(ee.Geometry.Point(-122.092, 37.42)) ) # Load a secondary collection: MODIS imagery. mod_secondary = ee.ImageCollection('MODIS/006/MOD09GA').filterDate( '2014-03-01', '2014-07-01' ) # Define an allowable time difference: two days in milliseconds. two_days_millis = 2 * 24 * 60 * 60 * 1000 # Create a time filter to define a match as overlapping timestamps. time_filter = ee.Filter.Or( ee.Filter.maxDifference( difference=two_days_millis, leftField='system:time_start', rightField='system:time_end', ), ee.Filter.maxDifference( difference=two_days_millis, leftField='system:time_end', rightField='system:time_start', ), ) # Define the join. save_all_join = ee.Join.saveAll( matchesKey='terra', ordering='system:time_start', ascending=True ) # Apply the join. landsat_modis = save_all_join.apply(primary, mod_secondary, time_filter) # Display the result. display('Join.saveAll:', landsat_modis)
請注意,在此範例中,secondary
MODIS 集合會預先篩選,以便與 primary
Landsat 集合在時間上保持一致,以提高效率。為了比較 Landsat 擷取時間與 MODIS 合成時間 (具有每日範圍),篩選器會比較圖片時間戳記的端點。此彙整作業的定義包含屬性名稱,用於儲存每張 Landsat 影像 (‘terra’
) 的比對清單,以及可選參數,用於依 system:time_start
屬性排序比對清單
檢查結果顯示,主要集合內的圖片已新增 terra
屬性,用於儲存相符的 MODIS 圖片清單。