图片概览

如“入门 ”文档中所述,栅格数据在 Earth Engine 中表示为 Image 对象。图片由一个或多个波段组成,每个波段都有自己的名称、数据类型、比例、掩码 和投影。每张图片都有元数据,这些元数据以一组属性的形式存储。

ee.Image 构造函数

您可以通过将 Earth Engine 资产 ID 粘贴到 ee.Image 构造函数中来加载图片。您可以在Data Catalog中找到图片 ID。例如,对于数字高程模型 (NASADEM):

代码编辑器 (JavaScript)

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

Python 设置

如需了解 Python API 和如何使用 geemap 进行交互式开发,请访问 Python 环境页面。

import ee
import geemap.core as geemap

Colab (Python)

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

请注意,通过 代码编辑器搜索工具 查找图片是等效的。导入资产时,系统会在代码编辑器的导入部分为您编写图片构造代码。您还可以使用个人 资产 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 API 和如何使用 geemap 进行交互式开发,请访问 Python 环境页面。

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() 从 Cloud Optimized GeoTIFFs 在 Google Cloud Storage 中加载图片。 例如,托管在 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 API 和如何使用 geemap 进行交互式开发,请访问 Python 环境页面。

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 Optimized GeoTIFF,请在导出时将 cloudOptimized 设置为 true ,如此处所述 here。

性能提示: 为了获得最佳性能,我们建议您 注册 COG 作为资产,而不是使用 ee.Image.loadGeoTIFF() 直接加载它们。如需了解详情和比较信息,请参阅 Cloud Optimized GeoTIFF (COG) 概览。

来自 Zarr v2 数组的图片

您可以使用 ee.Image.loadZarrV2Array() 从 Zarr v2 数组在 Google Cloud Storage中加载图片。例如,托管在 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 API 和如何使用 geemap 进行交互式开发,请访问 Python 环境页面。

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 API 和如何使用 geemap 进行交互式开发,请访问 Python 环境页面。

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)