שמירת צירופים היא אחת מהדרכים לייצוג יחסי אחד-ל-רבים ב-Earth Engine.
בניגוד לצירוף פנימי, צירוף לשמירה מאחסן התאמות מהאוסף secondary
כמאפיין בעל שם של התכונות באוסף primary
. כדי לשמור את כל ההתאמות האלה, משתמשים ב-ee.Join.saveAll()
. אם יש קשר אחד-ל-רבים, saveAll()
מחברת את כל התכונות התואמות כ-ee.List
. רכיבים שלא מתאימים באוסף primary
יוסרו. לדוגמה, נניח שצריך לקבל את כל התמונות של MODIS שנאספו תוך יומיים מכל תמונה של Landsat באוסף. בדוגמה הזו נעשה שימוש בחיבור saveAll()
למטרה הזו:
Code Editor (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 תואמות.