عمليات الربط الداخلي

لتعداد جميع المطابقات بين عناصر مجموعتَين، استخدِم ee.Join.inner(). الناتج من عملية الربط الداخلي هو FeatureCollection (حتى في حال ربط ImageCollection بImageCollection آخر). يمثّل كلّ عنصر في الناتج تطابقًا ، حيث يتم تخزين العناصر المطابقة في سمتَين للعنصر. على سبيل المثال،feature.get('primary') هو العنصر في المجموعة الأساسية الذي يتطابق مع العنصر من المجموعة الثانوية المخزّن في feature.get('secondary'). (يمكن تحديد أسماء مختلفة لهذه السمات كوسيطات inner()، ولكن ‘primary’ و ‘secondary’ هما الإعدادان التلقائيان). يتم تمثيل العلاقات بين عنصرَين من خلال ميزات متعددة في الإخراج. إذا لم يكن هناك تطابق بين عنصر في أيّ من المجموعتَين، لن يظهر في الناتج.

تنطبق أمثلة الدمج باستخدام مدخلات 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 للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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 للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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 للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام IDE geemap لتطوير التطبيقات التفاعلي.

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’) وجميع نطاقات الصورة المطابقة في المجموعة الثانوية (نطاقات الجودة).