圖片總覽

開始使用文件所述,Earth Engine 會將光柵資料表示為 Image 物件。影像由一或多個頻帶組成,每個頻帶都有自己的名稱、資料類型、比例、遮罩和投影。每張圖片的中繼資料都會以一組屬性儲存。

ee.Image 建構函式

您可以將 Earth Engine 資產 ID 貼到 ee.Image 建構函式中,藉此載入圖片。您可以在資料目錄中找到圖片 ID。例如,數位高程模型 (NASADEM):

程式碼編輯器 (JavaScript)

var loadedImage = ee.Image('NASA/NASADEM_HGT/001');

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

loaded_image = ee.Image('NASA/NASADEM_HGT/001')

請注意,透過程式碼編輯器搜尋工具尋找圖片的效果相同。匯入素材資源時,系統會在 Code Editor 的匯入部分中為您編寫圖片建構程式碼。您也可以使用個人資產 ID 做為 ee.Image 建構函式的引數。

ee.ImageCollection 取得 ee.Image

從集合中取得圖片的標準做法是篩選集合,並依特異性遞減順序排列篩選器。例如,如要從 Sentinel-2 地表反射率集合中取得圖像:

程式碼編輯器 (JavaScript)

var first = ee.ImageCollection('COPERNICUS/S2_SR')
                .filterBounds(ee.Geometry.Point(-70.48, 43.3631))
                .filterDate('2019-01-01', '2019-12-31')
                .sort('CLOUDY_PIXEL_PERCENTAGE')
                .first();
Map.centerObject(first, 11);
Map.addLayer(first, {bands: ['B4', 'B3', 'B2'], min: 0, max: 2000}, 'first');

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

first = (
    ee.ImageCollection('COPERNICUS/S2_SR')
    .filterBounds(ee.Geometry.Point(-70.48, 43.3631))
    .filterDate('2019-01-01', '2019-12-31')
    .sort('CLOUDY_PIXEL_PERCENTAGE')
    .first()
)

# Define a map centered on southern Maine.
m = geemap.Map(center=[43.7516, -70.8155], zoom=11)

# Add the image layer to the map and display it.
m.add_layer(
    first, {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 2000}, 'first'
)
display(m)

請注意,排序會在篩選條件「後方」執行。避免排序整個珍藏內容。

來自 Cloud GeoTIFF 的圖片

您可以使用 ee.Image.loadGeoTIFF()Google Cloud Storage 中的 Cloud Optimized GeoTIFF 載入圖片。舉例來說,在 Google Cloud 託管的 公開 Landsat 資料集包含 這個 GeoTIFF,對應 Landsat 8 場景的頻帶 5。您可以使用 ee.Image.loadGeoTIFF() 從 Cloud Storage 載入這張圖片:

程式碼編輯器 (JavaScript)

var uri = 'gs://gcp-public-data-landsat/LC08/01/001/002/' +
    'LC08_L1GT_001002_20160817_20170322_01_T2/' +
    'LC08_L1GT_001002_20160817_20170322_01_T2_B5.TIF';
var cloudImage = ee.Image.loadGeoTIFF(uri);
print(cloudImage);

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

uri = (
    'gs://gcp-public-data-landsat/LC08/01/001/002/'
    + 'LC08_L1GT_001002_20160817_20170322_01_T2/'
    + 'LC08_L1GT_001002_20160817_20170322_01_T2_B5.TIF'
)
cloud_image = ee.Image.loadGeoTIFF(uri)
display(cloud_image)

請注意,如果您想重新載入從 Earth Engine 匯出至 Cloud Storage的 Cloud 最佳化 GeoTIFF,請在匯出時將 cloudOptimized 設為 true,如這裡所述。

來自 Zarr v2 陣列的圖片

您可以使用 ee.Image.loadZarrV2Array()Google Cloud Storage 中的 Zarr v2 陣列載入圖片。舉例來說,Google Cloud 託管的公開 ERA5 資料集包含 這個 Zarr v2 陣列,對應地球表面蒸發的水量公尺。您可以使用 ee.Image.loadZarrV2Array() 從 Cloud Storage 載入這個陣列:

程式碼編輯器 (JavaScript)

var timeStart = 1000000;
var timeEnd = 1000010;
var zarrV2ArrayImage = ee.Image.loadZarrV2Array({
  uri:
      'gs://gcp-public-data-arco-era5/ar/full_37-1h-0p25deg-chunk-1.zarr-v3/evaporation/.zarray',
  proj: 'EPSG:4326',
  starts: [timeStart],
  ends: [timeEnd]
});
print(zarrV2ArrayImage);
Map.addLayer(zarrV2ArrayImage, {min: -0.0001, max: 0.00005}, 'Evaporation');

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

time_start = 1000000
time_end = 1000010
zarr_v2_array_image = ee.Image.loadZarrV2Array(
    uri='gs://gcp-public-data-arco-era5/ar/full_37-1h-0p25deg-chunk-1.zarr-v3/evaporation/.zarray',
    proj='EPSG:4326',
    starts=[time_start],
    ends=[time_end],
)

display(zarr_v2_array_image)

m.add_layer(
    zarr_v2_array_image, {'min': -0.0001, 'max': 0.00005}, 'Evaporation'
)
m

常數圖片

除了依 ID 載入圖片,您也可以使用常數、清單或其他合適的 Earth Engine 物件建立圖片。以下是建立圖片、取得頻帶子集和操作頻帶的方法:

程式碼編輯器 (JavaScript)

// Create a constant image.
var image1 = ee.Image(1);
print(image1);

// Concatenate two images into one multi-band image.
var image2 = ee.Image(2);
var image3 = ee.Image.cat([image1, image2]);
print(image3);

// Create a multi-band image from a list of constants.
var multiband = ee.Image([1, 2, 3]);
print(multiband);

// Select and (optionally) rename bands.
var renamed = multiband.select(
    ['constant', 'constant_1', 'constant_2'], // old names
    ['band1', 'band2', 'band3']               // new names
);
print(renamed);

// Add bands to an image.
var image4 = image3.addBands(ee.Image(42));
print(image4);

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

# Create a constant image.
image_1 = ee.Image(1)
display(image_1)

# Concatenate two images into one multi-band image.
image_2 = ee.Image(2)
image_3 = ee.Image.cat([image_1, image_2])
display(image_3)

# Create a multi-band image from a list of constants.
multiband = ee.Image([1, 2, 3])
display(multiband)

# Select and (optionally) rename bands.
renamed = multiband.select(
    ['constant', 'constant_1', 'constant_2'],  # old names
    ['band1', 'band2', 'band3'],  # new names
)
display(renamed)

# Add bands to an image.
image_4 = image_3.addBands(ee.Image(42))
display(image_4)