ee.data.computePixels (Python only)

通过对图片数据执行任意计算来计算图块。

返回: 以原始图片数据形式返回的像素。

用法返回
ee.data.computePixels(params)对象|值
参数类型详细信息
params对象一个包含参数的对象,参数可具有以下可能的值:
expression - 要计算的表达式。
fileFormat - 生成的文件格式。默认值为 png。如需了解可用的格式,请参阅 ImageFileFormat。还有其他格式可将下载的对象转换为 Python 数据对象。其中包括: NUMPY_NDARRAY,用于转换为结构化 NumPy 数组。
grid - 用于描述要从中提取数据的像素网格的参数。 默认为数据的原生像素网格。
bandIds - 如果存在,则指定要从中获取像素的一组特定波段。
visualizationOptions - 如果存在,则为一组可视化选项,用于生成数据的 8 位 RGB 可视化效果,而不是返回原始数据。
workloadTag - 用户提供的用于跟踪相应计算的标记。

示例

Python 设置

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

import ee
import geemap.core as geemap

Colab (Python)

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

# Sentinel-2 median composite.
image = (ee.ImageCollection('COPERNICUS/S2')
              .filterBounds(region)
              .filterDate('2020-04-01', '2020-09-01')
              .median())

# 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 = {
    'expression': image,
    '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.computePixels(request)
# Do something with the image...