如使用入门文档中所述,在 Earth Engine 中,栅格数据以 Image
对象表示。图片由一个或多个波段组成,每个波段都有自己的名称、数据类型、比例、掩码和投影。每张图片都包含以一组属性形式存储的元数据。
ee.Image
构造函数
通过将 Earth Engine 资产 ID 粘贴到 ee.Image
构造函数中,即可加载图片。您可以在数据目录中找到图片 ID。
例如,对于数字高程模型 (NASADEM):
代码编辑器 (JavaScript)
var loadedImage = ee.Image('NASA/NASADEM_HGT/001');
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');
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)
请注意,排序是在过滤之后进行的。避免对整个集合进行排序。
来自云 GeoTIFF 的图片
您可以使用 ee.Image.loadGeoTIFF()
从 Google Cloud Storage 中的云优化 GeoTIFF 加载图片。
例如,Google Cloud 中托管的公开 Landsat 数据集包含此 GeoTIFF,该 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);
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,如此处所述。
来自 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');
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);
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)