ee.data.getPixels (Python only)

從圖片素材資源擷取像素。

傳回: 以原始圖片資料形式傳回像素。

用量傳回
ee.data.getPixels(params)物件|值
引數類型詳細資料
params物件物件,內含參數,可能的值如下:
assetId - 要取得像素的資產 ID。必須是圖片素材資源。
fileFormat:產生的檔案格式。預設值為 png。如需可用格式,請參閱「ImageFileFormat」。此外,還有其他格式可將下載的物件轉換為 Python 資料物件。包括: NUMPY_NDARRAY,可轉換為結構化 NumPy 陣列。
grid - 描述要擷取資料的像素格線的參數。 預設為資料的原生像素格線。
region - 如果存在,則為要傳回的資料區域,指定為 GeoJSON 幾何物件 (請參閱 RFC 7946)。
bandIds - 如果存在,則指定要從中取得像素的特定頻帶組合。
visualizationOptions - 如果存在,則為一組要套用的視覺化選項,用來產生資料的 8 位元 RGB 視覺化結果,而不是傳回原始資料。

範例

Python 設定

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

import ee
import geemap.core as geemap

Colab (Python)

# Region of interest.
coords = [
    -121.58626826832939,
    38.059141484827485,
]
region = ee.Geometry.Point(coords)

# Get a Sentinel-2 image.
image = (ee.ImageCollection('COPERNICUS/S2')
  .filterBounds(region)
  .filterDate('2020-04-01', '2020-09-01')
  .sort('CLOUD_COVERAGE_ASSESSMENT')
  .first())
image_id = image.getInfo()['id']

# Make a projection to discover the scale in degrees.
proj = ee.Projection('EPSG:4326').atScale(10).getInfo()

# Get scales out of the transform.
scale_x = proj['transform'][0]
scale_y = -proj['transform'][4]

# Make a request object.
request = {
    'assetId': image_id,
    'fileFormat': 'PNG',
    'bandIds': ['B4', 'B3', 'B2'],
    'grid': {
        'dimensions': {
            'width': 640,
            'height': 640
        },
        'affineTransform': {
            'scaleX': scale_x,
            'shearX': 0,
            'translateX': coords[0],
            'shearY': 0,
            'scaleY': scale_y,
            'translateY': coords[1]
        },
        'crsCode': proj['crs'],
    },
    'visualizationOptions': {'ranges': [{'min': 0, 'max': 3000}]},
}

image_png = ee.data.getPixels(request)
# Do something with the image...