किसी ImageCollection पर मैपिंग करना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
ImageCollection
में मौजूद हर Image
पर कोई फ़ंक्शन लागू करने के लिए,
imageCollection.map()
का इस्तेमाल करें. map()
का एक ही आर्ग्युमेंट एक ऐसा फ़ंक्शन है जो एक पैरामीटर लेता है: ee.Image
. उदाहरण के लिए, यहां दिया गया कोड, संग्रह की हर इमेज में टाइमस्टैंप बैंड जोड़ता है.
कोड एडिटर (JavaScript)
// 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()
का इस्तेमाल किया जा सकता है. उदाहरण के लिए:
कोड एडिटर (JavaScript)
// 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()
का इस्तेमाल न करें और इसके बजाय फ़िल्टर का इस्तेमाल करें.
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eThe \u003ccode\u003eimageCollection.map()\u003c/code\u003e function applies a specified function to each image within an ImageCollection in Earth Engine.\u003c/p\u003e\n"],["\u003cp\u003eThe function passed to \u003ccode\u003emap()\u003c/code\u003e should accept a single \u003ccode\u003eee.Image\u003c/code\u003e as input and return a modified image.\u003c/p\u003e\n"],["\u003cp\u003eWhile mapped functions have limitations like not modifying external variables or using conventional loops, conditional operations are achievable using \u003ccode\u003eee.Algorithms.If()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eDespite the availability of \u003ccode\u003eee.Algorithms.If()\u003c/code\u003e, prioritize using filters for conditional logic whenever possible for better efficiency and code clarity.\u003c/p\u003e\n"]]],["To apply a function to each `Image` in an `ImageCollection`, use `imageCollection.map()`, providing a function that takes an `ee.Image` as input. This function can add bands, such as a timestamp using `image.addBands(image.getNumber('system:time_start'))`. Conditional logic can be implemented within the mapped function using `ee.Algorithms.If()`, allowing for operations based on image properties like solar elevation, though filtering is preferred. This conditional process is server-side and operates on the entire collection.\n"],null,["# Mapping over an ImageCollection\n\nTo apply a function to every `Image` in an `ImageCollection` use\n`imageCollection.map()`. The only argument to `map()` is a\nfunction which takes one parameter: an `ee.Image`. For example, the following\ncode adds a timestamp band to every image in the collection.\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Landsat 8 collection for a single path-row, 2021 images only.\nvar collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filterDate('2021', '2022')\n .filter(ee.Filter.eq('WRS_PATH', 44))\n .filter(ee.Filter.eq('WRS_ROW', 34));\n\n// This function adds a band representing the image timestamp.\nvar addTime = function(image) {\n return image.addBands(image.getNumber('system:time_start'));\n};\n\n// Map the function over the collection and display the result.\nprint(collection.map(addTime));\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Load a Landsat 8 collection for a single path-row, 2021 images only.\ncollection = (\n ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filterDate('2021', '2022')\n .filter(ee.Filter.eq('WRS_PATH', 44))\n .filter(ee.Filter.eq('WRS_ROW', 34))\n)\n\n\n# This function adds a band representing the image timestamp.\ndef add_time(image):\n return image.addBands(image.getNumber('system:time_start'))\n\n\n# Map the function over the collection and display the result.\ndisplay(collection.map(add_time))\n```\n\nNote that in the predefined function, the `getNumber()` method is used\nto create a new `Image` from the numerical value of a property. As discussed in\nthe [Reducing](/earth-engine/guides/ic_reducing) and\n[Compositing](/earth-engine/guides/ic_composite_mosaic)\nsections, having the time band is useful for linear modeling of change and for making\ncomposites.\n\nThe mapped function is limited in the operations it can perform. Specifically, it can't\nmodify variables outside the function; it can't print anything; it can't use JavaScript and\nPython 'if' or 'for' statements. However, you can use `ee.Algorithms.If()` to\nperform conditional operations in a mapped function. For example:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Landsat 8 collection for a single path-row, 2021 images only.\nvar collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filterDate('2021', '2022')\n .filter(ee.Filter.eq('WRS_PATH', 44))\n .filter(ee.Filter.eq('WRS_ROW', 34));\n\n// This function uses a conditional statement to return the image if\n// the solar elevation \u003e 40 degrees. Otherwise it returns a \"zero image\".\nvar conditional = function(image) {\n return ee.Algorithms.If(ee.Number(image.get('SUN_ELEVATION')).gt(40),\n image,\n ee.Image(0));\n};\n\n// Map the function over the collection and print the result. Expand the\n// collection and note that 7 of the 22 images are now \"zero images'.\nprint('Expand this to see the result', collection.map(conditional));\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Load a Landsat 8 collection for a single path-row, 2021 images only.\ncollection = (\n ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')\n .filterDate('2021', '2022')\n .filter(ee.Filter.eq('WRS_PATH', 44))\n .filter(ee.Filter.eq('WRS_ROW', 34))\n)\n\n\n# This function uses a conditional statement to return the image if\n# the solar elevation \u003e 40 degrees. Otherwise it returns a \"zero image\".\ndef conditional(image):\n return ee.Algorithms.If(\n ee.Number(image.get('SUN_ELEVATION')).gt(40), image, ee.Image(0)\n )\n\n\n# Map the function over the collection and print the result. Expand the\n# collection and note that 7 of the 22 images are now \"zero images'.\ndisplay('Expand this to see the result', collection.map(conditional))\n```\n\nInspect the list of images in the output ImageCollection and note that when the\ncondition evaluated by the `If()` algorithm is true, the output contains a\nconstant image. Although this demonstrates a server-side conditional function\n([learn more about client vs. server in Earth Engine](/earth-engine/guides/client_server)),\navoid `If()` in general and use filters instead."]]