내부 조인

두 컬렉션의 요소 간에 일치하는 항목을 모두 열거하려면 ee.Join.inner()를 사용하세요. 내부 조인의 출력은 FeatureCollection입니다 (하나의 ImageCollection를 다른 ImageCollection에 조인하는 경우에도 마찬가지). 출력의 각 지형지물은 일치를 나타내며, 일치하는 요소는 지형지물의 두 속성에 저장됩니다. 예를 들어 feature.get('primary')feature.get('secondary')에 저장된 보조 컬렉션의 요소와 일치하는 기본 컬렉션의 요소입니다. 이러한 속성의 다른 이름은 inner()의 인수로 지정할 수 있지만 ‘primary’‘secondary’가 기본값입니다. 일대다 관계는 출력에서 여러 지형지물로 표현됩니다. 두 컬렉션의 요소 중 일치하는 요소가 없으면 출력에 포함되지 않습니다.

ImageCollection 입력을 사용하는 조인 예는 수정 없이 FeatureCollection 입력에 적용됩니다. FeatureCollectionImageCollection에 조인하거나 그 반대로 할 수도 있습니다. 다음과 같은 내부 조인의 예시를 살펴보세요.

코드 편집기 (JavaScript)

// Create the primary collection.
var primaryFeatures = ee.FeatureCollection([
  ee.Feature(null, {foo: 0, label: 'a'}),
  ee.Feature(null, {foo: 1, label: 'b'}),
  ee.Feature(null, {foo: 1, label: 'c'}),
  ee.Feature(null, {foo: 2, label: 'd'}),
]);

// Create the secondary collection.
var secondaryFeatures = ee.FeatureCollection([
  ee.Feature(null, {bar: 1, label: 'e'}),
  ee.Feature(null, {bar: 1, label: 'f'}),
  ee.Feature(null, {bar: 2, label: 'g'}),
  ee.Feature(null, {bar: 3, label: 'h'}),
]);

// Use an equals filter to specify how the collections match.
var toyFilter = ee.Filter.equals({
  leftField: 'foo',
  rightField: 'bar'
});

// Define the join.
var innerJoin = ee.Join.inner('primary', 'secondary');

// Apply the join.
var toyJoin = innerJoin.apply(primaryFeatures, secondaryFeatures, toyFilter);

// Print the result.
print('Inner join toy example:', toyJoin);

Python 설정

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

import ee
import geemap.core as geemap

Colab (Python)

# Create the primary collection.
primary_features = ee.FeatureCollection([
    ee.Feature(None, {'foo': 0, 'label': 'a'}),
    ee.Feature(None, {'foo': 1, 'label': 'b'}),
    ee.Feature(None, {'foo': 1, 'label': 'c'}),
    ee.Feature(None, {'foo': 2, 'label': 'd'}),
])

# Create the secondary collection.
secondary_features = ee.FeatureCollection([
    ee.Feature(None, {'bar': 1, 'label': 'e'}),
    ee.Feature(None, {'bar': 1, 'label': 'f'}),
    ee.Feature(None, {'bar': 2, 'label': 'g'}),
    ee.Feature(None, {'bar': 3, 'label': 'h'}),
])

# Use an equals filter to specify how the collections match.
toy_filter = ee.Filter.equals(leftField='foo', rightField='bar')

# Define the join.
inner_join = ee.Join.inner('primary', 'secondary')

# Apply the join.
toy_join = inner_join.apply(primary_features, secondary_features, toy_filter)

# Print the result.
display('Inner join toy example:', toy_join)

이전 예에서 테이블 간의 관계는 필터에 정의되어 있으며, 이는 필드 ‘foo’‘bar’가 조인 필드임을 나타냅니다. 그런 다음 내부 조인이 지정되고 컬렉션에 적용됩니다. 출력을 검사하고 가능한 각 일치가 하나의 Feature로 표시되는지 확인합니다.

동기를 부여하는 예로 MODIS ImageCollection 객체를 조인하는 경우를 생각해 보세요. MODIS 품질 데이터는 이미지 데이터와 별도의 컬렉션에 저장되는 경우가 있으므로 품질 데이터를 적용하기 위해 두 컬렉션을 조인하는 데 내부 조인이 편리합니다. 이 경우 이미지 획득 시간이 동일하므로 등식 필터가 두 컬렉션 간의 이 관계를 지정하는 작업을 처리합니다.

코드 편집기 (JavaScript)

// Make a date filter to get images in this date range.
var dateFilter = ee.Filter.date('2014-01-01', '2014-02-01');

// Load a MODIS collection with EVI data.
var mcd43a4 = ee.ImageCollection('MODIS/MCD43A4_006_EVI')
    .filter(dateFilter);

// Load a MODIS collection with quality data.
var mcd43a2 = ee.ImageCollection('MODIS/006/MCD43A2')
    .filter(dateFilter);

// Define an inner join.
var innerJoin = ee.Join.inner();

// Specify an equals filter for image timestamps.
var filterTimeEq = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

// Apply the join.
var innerJoinedMODIS = innerJoin.apply(mcd43a4, mcd43a2, filterTimeEq);

// Display the join result: a FeatureCollection.
print('Inner join output:', innerJoinedMODIS);

Python 설정

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

import ee
import geemap.core as geemap

Colab (Python)

# Make a date filter to get images in this date range.
date_filter = ee.Filter.date('2014-01-01', '2014-02-01')

# Load a MODIS collection with EVI data.
mcd43a4 = ee.ImageCollection('MODIS/MCD43A4_006_EVI').filter(date_filter)

# Load a MODIS collection with quality data.
mcd43a2 = ee.ImageCollection('MODIS/006/MCD43A2').filter(date_filter)

# Define an inner join.
inner_join = ee.Join.inner()

# Specify an equals filter for image timestamps.
filter_time_eq = ee.Filter.equals(
    leftField='system:time_start', rightField='system:time_start'
)

# Apply the join.
inner_joined_modis = inner_join.apply(mcd43a4, mcd43a2, filter_time_eq)

# Display the join result: a FeatureCollection.
display('Inner join output:', inner_joined_modis)

출력 FeatureCollection에서 결합된 이미지를 사용하려면 map()을 사용합니다. map()은 출력에 대한 결합 함수입니다. 예를 들어 일치하는 이미지를 쌓아 품질 밴드가 이미지 데이터에 추가될 수 있습니다.

코드 편집기 (JavaScript)

// Map a function to merge the results in the output FeatureCollection.
var joinedMODIS = innerJoinedMODIS.map(function(feature) {
  return ee.Image.cat(feature.get('primary'), feature.get('secondary'));
});

// Print the result of merging.
print('Inner join, merged bands:', joinedMODIS);

Python 설정

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

import ee
import geemap.core as geemap

Colab (Python)

# Map a function to merge the results in the output FeatureCollection.
joined_modis = inner_joined_modis.map(
    lambda feature: ee.Image.cat(
        feature.get('primary'), feature.get('secondary')
    )
)

# Print the result of merging.
display("Inner join, merged 'bands':", joined_modis)

이 함수는 FeatureCollection에 매핑되지만 결과는 ImageCollection입니다. 결과 ImageCollection의 각 이미지에는 기본 컬렉션 (이 예에서는 ‘EVI’만 해당)의 이미지에 있는 모든 밴드와 보조 컬렉션의 일치하는 이미지에 있는 모든 밴드(품질 밴드)가 있습니다.