दो कलेक्शन के एलिमेंट के बीच मैच होने वाले सभी एलिमेंट की गिनती करने के लिए, ee.Join.inner()
का इस्तेमाल करें. इनर जॉइन का आउटपुट एक
FeatureCollection
होता है. भले ही, एक ImageCollection
को किसी दूसरी ImageCollection
से जोड़ा गया हो. आउटपुट में मौजूद हर सुविधा, एक मैच दिखाती है. मैच करने वाले एलिमेंट, सुविधा की दो प्रॉपर्टी में सेव किए जाते हैं. उदाहरण के लिए, feature.get('primary')
, प्राइमरी कलेक्शन में मौजूद वह एलिमेंट है जो feature.get('secondary')
में सेव किए गए सेकंडरी कलेक्शन के एलिमेंट से मैच करता है. (inner()
के लिए आर्ग्युमेंट के तौर पर, इन प्रॉपर्टी के अलग-अलग नाम दिए जा सकते हैं. हालांकि, ‘primary’
और
‘secondary’
डिफ़ॉल्ट तौर पर सेट होते हैं). आउटपुट में, एक-से-कई रिलेशनशिप को कई सुविधाओं से दिखाया जाता है. अगर किसी भी कलेक्शन में मौजूद कोई एलिमेंट मैच नहीं करता है, तो वह आउटपुट में मौजूद नहीं होता.
ImageCollection
इनपुट का इस्तेमाल करके जॉइन किए गए उदाहरण, बिना किसी बदलाव के
FeatureCollection
इनपुट पर लागू होते हैं. FeatureCollection
को ImageCollection
से और ImageCollection
को FeatureCollection
से भी जोड़ा जा सकता है. इनर जॉइन के इस उदाहरण पर ध्यान दें:
कोड एडिटर (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);
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);
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);
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’
) में मौजूद इमेज के सभी बैंड और सेकंडरी कलेक्शन में मौजूद मैच करने वाली इमेज के सभी बैंड (क्वालिटी बैंड) होते हैं.