برای شمارش همه موارد منطبق بین عناصر دو مجموعه، از
ee.Join.inner() استفاده کنید. خروجی اتصال داخلی یک
FeatureCollection است (حتی اگر یک ImageCollection
به ImageCollection دیگری متصل شود). هر عارضه در خروجی نشاندهنده یک
تطابق است، که در آن عناصر منطبق در دو ویژگی عارضه ذخیره میشوند. برای مثال، feature.get('primary') عنصری در مجموعه اصلی است که با عنصر مجموعه فرعی ذخیرهشده در feature.get('secondary') مطابقت دارد. (نامهای متفاوت برای این ویژگیها را میتوان
بهعنوان آرگومان برای inner() مشخص کرد، اما ‘primary’ و
‘secondary’ پیشفرض هستند). رابطههای یکبهچند با چندین ویژگی در برونداد نشان داده میشود. اگر عنصری در هریک از مجموعهها مطابقت نداشته باشد، در خروجی وجود ندارد.
نمونههای پیوستن بااستفاده از ورودیهای ImageCollection بدون اصلاح در ورودیهای FeatureCollection اعمال میشود. همچنین میتوانید FeatureCollection را به ImageCollection و برعکس بپیوندید. مثال ساده زیر را برای اتصال داخلی درنظر بگیرید:
ویرایشگر کد (جاوا اسکریپت)
// 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 گاهی در مجموعهای جدا از دادههای تصویر ذخیره میشوند، بنابراین اتصال داخلی برای پیوستن دو مجموعه بهمنظور اعمال دادههای کیفیت مناسب است. در این مورد، زمانهای دریافت تصویر یکسان هستند، بنابراین فیلتر برابری
وظیفه مشخص کردن این رابطه بین دو مجموعه را برعهده دارد:
ویرایشگر کد (جاوا اسکریپت)
// 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/061/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/061/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() تابع ترکیبی روی خروجی. برای مثال، تصاویر منطبق را میتوان بهگونهای رویهم چید که نوارهای کیفیت به دادههای تصویر اضافه شوند:
ویرایشگر کد (جاوا اسکریپت)
// 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’) و همه باندهای تصویر منطبق در مجموعه ثانویه
(باندهای کیفیت) را دارد.