すべて保存結合

結合を保存することは、Earth Engine で 1 対多の関係を表す 1 つの方法です。保存結合は内部結合とは異なり、secondary コレクションの一致を primary コレクション内の特徴の名前付きプロパティとして保存します。このような一致をすべて保存するには、ee.Join.saveAll() を使用します。1 対多の関係がある場合、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 の合成時間(1 日間の範囲)を比較するため、このフィルタは画像のタイムスタンプの終端を比較します。結合は、各 Landsat 画像の一致リストの保存に使用されるプロパティの名前(‘terra’)と、system:time_start プロパティで一致リストを並べ替えるオプション パラメータで定義されます。

結果を調べると、プライマリ コレクション内の画像に、一致する MODIS 画像のリストを格納する terra プロパティが追加されていることがわかります。