একটি চিত্র সংগ্রহের উপর ম্যাপিং

একটি ImageCollection এর প্রতিটি Image একটি ফাংশন প্রয়োগ করতে imageCollection.map() ব্যবহার করুন। map() করার একমাত্র যুক্তি হল একটি ফাংশন যা একটি প্যারামিটার নেয়: একটি ee.Image । উদাহরণস্বরূপ, নিম্নলিখিত কোডটি সংগ্রহের প্রতিটি ছবিতে একটি টাইমস্ট্যাম্প ব্যান্ড যোগ করে।

কোড এডিটর (জাভাস্ক্রিপ্ট)

// Load a Landsat 8 collection for a single path-row, 2021 images only.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
  .filterDate('2021', '2022')
  .filter(ee.Filter.eq('WRS_PATH', 44))
  .filter(ee.Filter.eq('WRS_ROW', 34));

// This function adds a band representing the image timestamp.
var addTime = function(image) {
  return image.addBands(image.getNumber('system:time_start'));
};

// Map the function over the collection and display the result.
print(collection.map(addTime));

পাইথন সেটআপ

পাইথন এপিআই এবং ইন্টারেক্টিভ ডেভেলপমেন্টের জন্য geemap ব্যবহার করার জন্য পাইথন এনভায়রনমেন্ট পৃষ্ঠাটি দেখুন।

import ee
import geemap.core as geemap

Colab (পাইথন)

# Load a Landsat 8 collection for a single path-row, 2021 images only.
collection = (
    ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filterDate('2021', '2022')
    .filter(ee.Filter.eq('WRS_PATH', 44))
    .filter(ee.Filter.eq('WRS_ROW', 34))
)


# This function adds a band representing the image timestamp.
def add_time(image):
  return image.addBands(image.getNumber('system:time_start'))


# Map the function over the collection and display the result.
display(collection.map(add_time))

নোট করুন যে পূর্বনির্ধারিত ফাংশনে, getNumber() পদ্ধতিটি একটি সম্পত্তির সংখ্যাসূচক মান থেকে একটি নতুন Image তৈরি করতে ব্যবহৃত হয়। হ্রাসকরণ এবং সংমিশ্রণ বিভাগে যেমন আলোচনা করা হয়েছে, টাইম ব্যান্ড থাকা পরিবর্তনের লিনিয়ার মডেলিং এবং কম্পোজিট তৈরির জন্য দরকারী।

ম্যাপ করা ফাংশনটি সীমিত ক্রিয়াকলাপগুলির মধ্যে এটি সম্পাদন করতে পারে৷ বিশেষ করে, এটি ফাংশনের বাইরে ভেরিয়েবল পরিবর্তন করতে পারে না; এটা কিছু মুদ্রণ করতে পারে না; এটি জাভাস্ক্রিপ্ট এবং পাইথন 'if' বা 'for' বিবৃতি ব্যবহার করতে পারে না। যাইহোক, আপনি ee.Algorithms.If() ব্যবহার করতে পারেন একটি ম্যাপ করা ফাংশনে শর্তসাপেক্ষ অপারেশন করতে। যেমন:

কোড এডিটর (জাভাস্ক্রিপ্ট)

// Load a Landsat 8 collection for a single path-row, 2021 images only.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
  .filterDate('2021', '2022')
  .filter(ee.Filter.eq('WRS_PATH', 44))
  .filter(ee.Filter.eq('WRS_ROW', 34));

// This function uses a conditional statement to return the image if
// the solar elevation > 40 degrees. Otherwise it returns a "zero image".
var conditional = function(image) {
  return ee.Algorithms.If(ee.Number(image.get('SUN_ELEVATION')).gt(40),
                          image,
                          ee.Image(0));
};

// Map the function over the collection and print the result. Expand the
// collection and note that 7 of the 22 images are now "zero images'.
print('Expand this to see the result', collection.map(conditional));

পাইথন সেটআপ

পাইথন এপিআই এবং ইন্টারেক্টিভ ডেভেলপমেন্টের জন্য geemap ব্যবহার করার জন্য পাইথন এনভায়রনমেন্ট পৃষ্ঠাটি দেখুন।

import ee
import geemap.core as geemap

Colab (পাইথন)

# Load a Landsat 8 collection for a single path-row, 2021 images only.
collection = (
    ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filterDate('2021', '2022')
    .filter(ee.Filter.eq('WRS_PATH', 44))
    .filter(ee.Filter.eq('WRS_ROW', 34))
)


# This function uses a conditional statement to return the image if
# the solar elevation > 40 degrees. Otherwise it returns a "zero image".
def conditional(image):
  return ee.Algorithms.If(
      ee.Number(image.get('SUN_ELEVATION')).gt(40), image, ee.Image(0)
  )


# Map the function over the collection and print the result. Expand the
# collection and note that 7 of the 22 images are now "zero images'.
display('Expand this to see the result', collection.map(conditional))

আউটপুট ImageCollection-এ ছবিগুলির তালিকা পরিদর্শন করুন এবং লক্ষ্য করুন যে যদি If() অ্যালগরিদম দ্বারা মূল্যায়ন করা শর্তটি সত্য হয়, তখন আউটপুটে একটি ধ্রুবক চিত্র থাকে। যদিও এটি একটি সার্ভার-সাইড শর্তসাপেক্ষ ফাংশন প্রদর্শন করে ( আর্থ ইঞ্জিনে ক্লায়েন্ট বনাম সার্ভার সম্পর্কে আরও জানুন ), সাধারণভাবে If() এড়িয়ে চলুন এবং পরিবর্তে ফিল্টার ব্যবহার করুন।