컬렉션의 각 요소에 가장 적합한 항목만 저장하려면 ee.Join.saveBest()
를 사용하세요. saveBest()
조인은 saveAll()
조인과 동일한 방식으로 작동합니다. 단, primary
컬렉션의 각 요소를 제외하고 가장 일치하는 secondary
컬렉션의 요소를 저장합니다. 기본 컬렉션에서 일치하지 않는 요소는 삭제됩니다. primary
컬렉션의 각 Landsat 이미지와 가장 가까운 시간의 기상 이미지를 찾으려는 경우를 가정해 보겠습니다. 이 조인을 실행하려면 단일 조인 조건에 대해 ee.Filter
를 재정의해야 합니다. 여러 하위 필터의 순위를 결합하는 방법이 모호하므로 결합된 필터는 saveBest()
와 함께 작동하지 않습니다.
코드 편집기 (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: GRIDMET meteorological data var gridmet = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET'); // Define a max difference filter to compare timestamps. var maxDiffFilter = ee.Filter.maxDifference({ difference: 2 * 24 * 60 * 60 * 1000, leftField: 'system:time_start', rightField: 'system:time_start' }); // Define the join. var saveBestJoin = ee.Join.saveBest({ matchKey: 'bestImage', measureKey: 'timeDiff' }); // Apply the join. var landsatMet = saveBestJoin.apply(primary, gridmet, maxDiffFilter); // Print the result. print(landsatMet);
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: GRIDMET meteorological data gridmet = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET') # Define a max difference filter to compare timestamps. max_diff_filter = ee.Filter.maxDifference( difference=2 * 24 * 60 * 60 * 1000, leftField='system:time_start', rightField='system:time_start', ) # Define the join. save_best_join = ee.Join.saveBest(matchKey='bestImage', measureKey='timeDiff') # Apply the join. landsat_met = save_best_join.apply(primary, gridmet, max_diff_filter) # Print the result. display(landsat_met)
saveBest()
조인은 최적 일치를 저장할 속성 이름 (‘bestImage’
)과 일치도 측정항목의 품질을 저장할 속성 이름 (‘timeDiff’
)을 정의합니다. 결과를 검사하면 일치하는 DAYMET 이미지가 primary
컬렉션의 각 Landsat 장면의 bestImage
속성에 추가된 것을 알 수 있습니다. 이러한 DAYMET 이미지에는 DAYMET 이미지와 Landsat 이미지 간의 시간 차이(밀리초)를 나타내는 timeDiff
속성이 있으며, 이 속성은 필터의 조건을 통과하는 DAYMET 이미지 중 최소값입니다.