ee.ImageCollection.first

  • The first() function retrieves the first image from an ImageCollection in Earth Engine.

  • It can be applied to any ImageCollection, like the 'COPERNICUS/S2_SR' dataset shown in the examples.

  • Users can then visualize and analyze this single image, displaying its metadata or adding it as a layer to a map.

  • The provided code demonstrates using first() in both JavaScript and Python environments within the Google Earth Engine Code Editor and Colab.

Returns the first entry from a given collection.

UsageReturns
ImageCollection.first()Image
ArgumentTypeDetails
this: imagecollectionImageCollectionThe ImageCollection instance.

Examples

Code Editor (JavaScript)

var image = ee.ImageCollection('COPERNICUS/S2_SR').first();
Map.centerObject(image, 8);
var vis = {bands: ['B4', 'B3', 'B2'], min: 0, max: 5000};
Map.addLayer(image, vis, 'first of S2_SR');

// Display the image metadata.
print(image);

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

import ee
import geemap.core as geemap

Colab (Python)

image = ee.ImageCollection('COPERNICUS/S2_SR').first()
m = geemap.Map()
m.center_object(image, 8)
vis = {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 5000}
m.add_layer(image, vis, 'first of S2_SR')
display(m)

# Display the image metadata.
display(image)