ee.ImageCollection.getRegion

針對 ImageCollection 中的每個 [像素、波段、圖片] 元組,輸出值陣列。輸出內容包含 ID、經度、緯度、時間和所有波段的資料列,這些資料列對應於指定區域中與每個像素相交的每張圖片。如果嘗試擷取超過 1048576 個值,就會發生錯誤。

用量傳回
ImageCollection.getRegion(geometry, scale, crs, crsTransform)清單
引數類型詳細資料
這個:collectionImageCollection要從中擷取資料的圖片集。
geometry幾何圖形要擷取資料的區域。
scale浮點值,預設值為空值以公尺為單位的投影名義比例,用於工作。
crs投影 (選用)要使用的投影機。如未指定,則預設為 EPSG:4326。如果除了比例之外還指定了投影,系統會將投影重新調整為指定比例。
crsTransform清單,預設值為空值CRS 轉換值的陣列。這是 3x2 仿射轉換的列優先順序。這個選項與縮放選項互斥,且會取代指定投影中已設定的任何變形。

範例

程式碼編輯器 (JavaScript)

// A Landsat 8 TOA image collection (3 months at a specific point, RGB bands).
var col = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
  .filterBounds(ee.Geometry.Point(-90.70, 34.71))
  .filterDate('2020-07-01', '2020-10-01')
  .select('B[2-4]');
print('Collection', col);

// Define a region to get pixel values for. This is a small rectangle region
// that intersects 2 image pixels at 30-meter scale.
var roi = ee.Geometry.BBox(-90.496353, 34.851971, -90.495749, 34.852197);

// Display the region of interest overlaid on an image representative. Note
// the ROI intersection with 2 pixels.
var visParams = {
  bands: ['B4', 'B3', 'B2'],
  min: 0.128,
  max: 0.163
};
Map.setCenter(-90.49605, 34.85211, 19);
Map.addLayer(col.first(), visParams, 'Image representative');
Map.addLayer(roi, {color: 'white'}, 'ROI');

// Fetch pixel-level information from all images in the collection for the
// pixels intersecting the ROI.
var pixelInfoBbox = col.getRegion({
  geometry: roi,
  scale: 30
});

// The result is a table (a list of lists) where the first row is column
// labels and subsequent rows are image pixels. Columns contain values for
// the image ID ('system:index'), pixel longitude and latitude, image
// observation time ('system:time_start'), and bands. In this example, note
// that there are 5 images and the region intersects 2 pixels, so n rows
// equals 11 (5 * 2 + 1). All collection images must have the same number of
// bands with the same names.
print('Extracted pixel info', pixelInfoBbox);

// The function accepts all geometry types (e.g., points, lines, polygons).
// Here, a multi-point geometry with two points is used.
var points = ee.Geometry.MultiPoint([[-90.49, 34.85], [-90.48, 34.84]]);
var pixelInfoPoints = col.getRegion({
  geometry: points,
  scale: 30
});
print('Point geometry example', pixelInfoPoints);

Python 設定

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

import ee
import geemap.core as geemap

Colab (Python)

# A Landsat 8 TOA image collection (3 months at a specific point, RGB bands).
col = (
    ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filterBounds(ee.Geometry.Point(-90.70, 34.71))
    .filterDate('2020-07-01', '2020-10-01')
    .select('B[2-4]')
)
display('Collection', col)

# Define a region to get pixel values for. This is a small rectangle region
# that intersects 2 image pixels at 30-meter scale.
roi = ee.Geometry.BBox(-90.496353, 34.851971, -90.495749, 34.852197)

# Display the region of interest overlaid on an image representative. Note
# the ROI intersection with 2 pixels.
vis_params = {'bands': ['B4', 'B3', 'B2'], 'min': 0.128, 'max': 0.163}
m = geemap.Map()
m.set_center(-90.49605, 34.85211, 19)
m.add_layer(col.first(), vis_params, 'Image representative')
m.add_layer(roi, {'color': 'white'}, 'ROI')
display(m)

# Fetch pixel-level information from all images in the collection for the
# pixels intersecting the ROI.
pixel_info_bbox = col.getRegion(geometry=roi, scale=30)

# The result is a table (a list of lists) where the first row is column
# labels and subsequent rows are image pixels. Columns contain values for
# the image ID ('system:index'), pixel longitude and latitude, image
# observation time ('system:time_start'), and bands. In this example, note
# that there are 5 images and the region intersects 2 pixels, so n rows
# equals 11 (5 * 2 + 1). All collection images must have the same number of
# bands with the same names.
display('Extracted pixel info', pixel_info_bbox)

# The function accepts all geometry types (e.g., points, lines, polygons).
# Here, a multi-point geometry with two points is used.
points = ee.Geometry.MultiPoint([[-90.49, 34.85], [-90.48, 34.84]])
pixel_info_points = col.getRegion(geometry=points, scale=30)
display('Point geometry example', pixel_info_points)