Untuk menghitung semua kecocokan antara elemen dari dua koleksi, gunakan
ee.Join.inner()
. Output dari inner join adalah
FeatureCollection
(meskipun menggabungkan satu ImageCollection
ke ImageCollection
lain). Setiap fitur dalam output mewakili
kecocokan, dengan elemen yang cocok disimpan dalam dua properti fitur. Misalnya, feature.get('primary')
adalah elemen dalam koleksi utama
yang cocok dengan elemen dari koleksi sekunder yang disimpan di
feature.get('secondary')
. (Nama yang berbeda untuk properti ini dapat ditentukan sebagai argumen ke inner()
, tetapi ‘primary’
dan ‘secondary’
adalah default). Hubungan one-to-many direpresentasikan
oleh beberapa fitur dalam output. Jika elemen dalam salah satu koleksi tidak memiliki
kecocokan, elemen tersebut tidak akan ada dalam output.
Contoh join menggunakan input ImageCollection
berlaku tanpa modifikasi pada
input FeatureCollection
. Anda juga dapat menggabungkan
FeatureCollection
ke ImageCollection
dan sebaliknya. Pertimbangkan
contoh sederhana join dalam berikut:
// 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);
import ee import geemap.core as geemap
# 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)
Pada contoh sebelumnya, perhatikan bahwa hubungan antartabel ditentukan dalam
filter, yang menunjukkan bahwa kolom ‘foo’
dan ‘bar’
adalah
kolom join. Join dalam kemudian ditentukan dan diterapkan ke koleksi. Periksa
output dan amati bahwa setiap kemungkinan kecocokan direpresentasikan sebagai satu
Feature
.
Untuk contoh yang termotivasi, pertimbangkan untuk menggabungkan objek ImageCollection
MODIS. Data kualitas MODIS
terkadang disimpan dalam koleksi terpisah dari data gambar, sehingga
join dalam sangat mudah untuk menggabungkan kedua koleksi guna menerapkan data
kualitas. Dalam hal ini, waktu akuisisi gambar identik, sehingga filter sama menangani tugas menentukan hubungan ini antara dua koleksi:
// 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);
import ee import geemap.core as geemap
# 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)
Untuk menggunakan gambar yang digabungkan dalam output FeatureCollection
,
map()
fungsi penggabungan atas output. Misalnya, gambar yang cocok
dapat ditumpuk sehingga band kualitas ditambahkan ke data gambar:
// 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);
import ee import geemap.core as geemap
# 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)
Meskipun fungsi ini dipetakan di atas FeatureCollection
, hasilnya adalah
ImageCollection
. Setiap gambar dalam ImageCollection
yang dihasilkan
memiliki semua band gambar dalam koleksi utama (dalam contoh ini hanya
‘EVI’
) dan semua band gambar yang cocok dalam koleksi sekunder
(band kualitas).