ImageCollection-এর উপর ম্যাপ করুন

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));

Python সেট-আপ

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

import ee
import geemap.core as geemap

Colab (Python)

# 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))

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

ম্যাপ করা ফাংশনটি যে অপারেশনগুলি করতে পারে তাতে সীমাবদ্ধ। বিশেষ করে, এটি ফাংশনের বাইরে ভেরিয়েবল পরিবর্তন করতে পারে না; এটি কিছু প্রিন্ট করতে পারে না; এটি JavaScript এবং Python '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));

Python সেট-আপ

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

import ee
import geemap.core as geemap

Colab (Python)

# 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() অ্যালগরিদম দ্বারা মূল্যায়ন করা শর্তটি সত্য হলে, আউটপুটে একটি ধ্রুবক ছবি থাকে। যদিও এটি সার্ভার-সাইড কন্ডিশনাল ফাংশন দেখায় (Earth Engine-এ ক্লায়েন্ট বনাম সার্ভার সম্পর্কে আরও জানুন), সাধারণত If() এড়িয়ে চলুন এবং এর পরিবর্তে ফিল্টার ব্যবহার করুন।