การรวมภายใน

หากต้องการแสดงรายการรายการที่ตรงกันทั้งหมดระหว่างองค์ประกอบของคอลเล็กชัน 2 รายการ ให้ใช้ ee.Join.inner() เอาต์พุตของการรวมภายในคือ FeatureCollection (แม้ว่าจะรวม ImageCollection รายการหนึ่งเข้ากับ ImageCollection รายการอื่นก็ตาม) ฟีเจอร์แต่ละรายการในเอาต์พุตแสดงถึงการจับคู่ โดยระบบจะจัดเก็บองค์ประกอบที่ตรงกันในพร็อพเพอร์ตี้ 2 รายการของฟีเจอร์ ตัวอย่างเช่น feature.get('primary') คือองค์ประกอบในคอลเล็กชันหลักที่ตรงกับองค์ประกอบจากคอลเล็กชันรองที่จัดเก็บไว้ใน feature.get('secondary') (คุณระบุชื่ออื่นสำหรับพร็อพเพอร์ตี้เหล่านี้เป็นอาร์กิวเมนต์ของ inner() ได้ แต่ ‘primary’ และ ‘secondary’ เป็นค่าเริ่มต้น) ความสัมพันธ์แบบ 1:หลายรายการจะแสดงด้วยฟีเจอร์หลายรายการในเอาต์พุต หากองค์ประกอบในคอลเล็กชันใดคอลเล็กชันหนึ่งไม่มีรายการที่ตรงกัน องค์ประกอบดังกล่าวจะไม่แสดงในเอาต์พุต

ตัวอย่างการรวมโดยใช้อินพุต ImageCollection ใช้โดยไม่มีการแก้ไขอินพุต FeatureCollection นอกจากนี้ คุณยังเข้าร่วมFeatureCollectionกับImageCollectionและในทางกลับกันได้ ลองดูตัวอย่างการเข้าร่วมภายในต่อไปนี้

เครื่องมือแก้ไขโค้ด (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 จะจัดเก็บไว้ในคอลเล็กชันแยกต่างหากจากข้อมูลรูปภาพ การรวมภายในจึงสะดวกสำหรับการรวม 2 คอลเล็กชันเข้าด้วยกันเพื่อใช้ข้อมูลคุณภาพ ในกรณีนี้ เวลาที่รับภาพจะเหมือนกัน ดังนั้นตัวกรอง "เท่ากับ" จะจัดการงานในการระบุความสัมพันธ์นี้ระหว่างคอลเล็กชัน 2 รายการ

เครื่องมือแก้ไขโค้ด (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()ฟังก์ชันการรวมกับเอาต์พุต ตัวอย่างเช่น คุณสามารถซ้อนรูปภาพที่ตรงกันไว้ด้วยกันเพื่อให้ระบบเพิ่มแถบคุณภาพลงในข้อมูลรูปภาพได้ ดังนี้

เครื่องมือแก้ไขโค้ด (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’) และแถบทั้งหมดของรูปภาพที่ตรงกันในคอลเล็กชันรอง (แถบคุณภาพ)