Liên kết đơn giản

Một phép nối đơn giản sẽ trả về các phần tử từ tập hợp primary khớp với bất kỳ phần tử nào trong tập hợp secondary theo điều kiện khớp trong bộ lọc. Để thực hiện một phép nối đơn giản, hãy sử dụng ee.Join.simple(). Điều này có thể hữu ích khi tìm các phần tử chung giữa các bộ sưu tập hoặc lọc một bộ sưu tập theo một bộ sưu tập khác. Ví dụ: hãy xem xét hai bộ sưu tập hình ảnh (có thể) có một số phần tử khớp, trong đó "khớp" được xác định theo điều kiện được chỉ định trong bộ lọc. Ví dụ: hãy cho rằng việc khớp nghĩa là mã nhận dạng hình ảnh bằng nhau. Vì các hình ảnh trùng khớp trong cả hai bộ sưu tập đều giống nhau, hãy sử dụng một phép nối đơn giản để khám phá tập hợp hình ảnh trùng khớp này:

Trình soạn thảo mã (JavaScript)

// Load a Landsat 8 image collection at a point of interest.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filterBounds(ee.Geometry.Point(-122.09, 37.42));

// Define start and end dates with which to filter the collections.
var april = '2014-04-01';
var may = '2014-05-01';
var june = '2014-06-01';
var july = '2014-07-01';

// The primary collection is Landsat images from April to June.
var primary = collection.filterDate(april, june);

// The secondary collection is Landsat images from May to July.
var secondary = collection.filterDate(may, july);

// Use an equals filter to define how the collections match.
var filter = ee.Filter.equals({
  leftField: 'system:index',
  rightField: 'system:index'
});

// Create the join.
var simpleJoin = ee.Join.simple();

// Apply the join.
var simpleJoined = simpleJoin.apply(primary, secondary, filter);

// Display the result.
print('Simple join: ', simpleJoined);

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap để phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

# Load a Landsat 8 image collection at a point of interest.
collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA').filterBounds(
    ee.Geometry.Point(-122.09, 37.42)
)

# Define start and end dates with which to filter the collections.
april = '2014-04-01'
may = '2014-05-01'
june = '2014-06-01'
july = '2014-07-01'

# The primary collection is Landsat images from April to June.
primary = collection.filterDate(april, june)

# The secondary collection is Landsat images from May to July.
secondary = collection.filterDate(may, july)

# Use an equals filter to define how the collections match.
filter = ee.Filter.equals(leftField='system:index', rightField='system:index')

# Create the join.
simple_join = ee.Join.simple()

# Apply the join.
simple_joined = simple_join.apply(primary, secondary, filter)

# Display the result.
display('Simple join:', simple_joined)

Trong ví dụ trước, hãy quan sát thấy các bộ sưu tập cần kết hợp trùng lặp về thời gian khoảng một tháng. Xin lưu ý rằng khi áp dụng mối liên kết này, kết quả sẽ là một ImageCollection chỉ chứa các hình ảnh trùng khớp trong tập hợp primary. Kết quả sẽ có dạng như sau:

Image LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140505 (17 bands)
Image LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140521 (17 bands)

Kết quả này cho thấy hai hình ảnh khớp nhau (như đã chỉ định trong bộ lọc) giữa các bộ sưu tập primarysecondary, hình ảnh vào ngày 5 tháng 5 và ngày 21 tháng 5.