การบันทึกการเข้าร่วมเป็นวิธีหนึ่งในการนำเสนอความสัมพันธ์แบบ 1 ต่อหลายรายการใน Earth Engine
การเข้าร่วมแบบบันทึกจะจัดเก็บรายการที่ตรงกันจากคอลเล็กชัน secondary
เป็นพร็อพเพอร์ตี้ที่มีชื่อของฟีเจอร์ในคอลเล็กชัน primary
ซึ่งแตกต่างจากการเข้าร่วมภายใน หากต้องการบันทึกรายการที่ตรงกันทั้งหมดดังกล่าว ให้ใช้
ee.Join.saveAll()
หากมีความสัมพันธ์แบบ 1: หลาย saveAll()
join จะจัดเก็บฟีเจอร์ที่ตรงกันทั้งหมดเป็น ee.List
ระบบจะทิ้งองค์ประกอบที่ตรงกันไม่ได้ในคอลเล็กชัน primary
ตัวอย่างเช่น สมมติว่าจำเป็นต้องรับภาพ MODIS ทั้งหมดภายใน 2 วันหลังจากภาพ Landsat แต่ละภาพในคอลเล็กชัน ตัวอย่างนี้ใช้การเข้าร่วม 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 ที่ตรงกัน