Save-All 조인

조인 저장은 Earth Engine에서 일대다 관계를 나타내는 한 가지 방법입니다. 저장 조인은 내부 조인과 달리 secondary 컬렉션의 일치를 primary 컬렉션의 지형지물의 이름이 지정된 속성으로 저장합니다. 이러한 일치를 모두 저장하려면 ee.Join.saveAll()를 사용하세요. 일대다 관계가 있는 경우 saveAll() 조인은 일치하는 모든 지형지물을 ee.List로 저장합니다. primary 컬렉션에서 일치하지 않는 요소는 삭제됩니다. 예를 들어 컬렉션의 각 Landsat 이미지로부터 2일 이내에 획득된 모든 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);

Python 설정

Python API 및 대화형 개발을 위한 geemap 사용에 관한 자세한 내용은 Python 환경 페이지를 참고하세요.

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 속성별로 일치 항목 목록을 정렬하는 선택적 매개변수로 정의됩니다.

결과를 검사하면 기본 컬렉션 내 이미지에 일치하는 MODIS 이미지 목록을 저장하는 terra 속성이 추가된 것을 알 수 있습니다.