如「開始使用」一文所述,在 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')
請注意,透過程式碼編輯器搜尋工具尋找圖片的效果相同。匯入資產時,系統會在 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');
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 中的雲端最佳化 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);
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 第 2 版陣列中的圖片
您可以使用 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)