ee.data.getDownloadId

获取下载 ID。

返回下载 ID 和令牌,如果指定了回调,则返回 null。

用法返回
ee.data.getDownloadId(params, callback)DownloadId
参数类型详细信息
params对象一个包含下载选项的对象,可用的值如下:
name: 用于构建文件名的基本名称。仅当格式为“ZIPPED_GEO_TIFF”(默认)、“ZIPPED_GEO_TIFF_PER_BAND”或 filePerBand 为 true 时适用。如果格式为“ZIPPED_GEO_TIFF”“ZIPPED_GEO_TIFF_PER_BAND”或 filePerBand 为 true,则默认为图片 ID(对于计算出的图片,则为“download”),否则会生成随机字符串。如果 filePerBand 为 true,则会附加频段名称。
bands: 要下载的波段的说明。必须是频段名称数组或字典数组,每个字典都包含以下键(可选参数仅在 filePerBand 为 true 时适用):
  • id: 频段的名称,字符串,必需。
  • crs: 定义频段投影的可选 CRS 字符串。
  • crs_transform: 一个可选的 6 个数字的数组,用于指定从指定 CRS 开始的仿射转换,按行优先顺序排列:[xScale, xShearing, xTranslation, yShearing, yScale, yTranslation]
  • dimensions: 一个可选的整数数组,包含两个整数,用于定义频段的裁剪宽度和高度。
  • scale: 一个可选的数字,用于指定频段的比例(以米为单位);如果指定了 crs 和 crs_transform,则忽略此参数。
crs: 要用于未明确指定 CRS 字符串的任何频段的默认 CRS 字符串。
crs_transform: 要用于未指定仿射转换的任何频段的默认仿射转换,格式与频段的 crs_transform 相同。
要用于未指定图片剪裁维度的任何频段的 dimensions: 默认图片剪裁维度。
scale: 要用于未指定比例的任何频段的默认比例;如果指定了 crscrs_transform,则忽略此参数。
region: 指定要下载的区域的多边形;如果指定了 crscrs_transform,则忽略此参数。
filePerBand: 是否为每个波段生成单独的 GeoTIFF(布尔值)。默认值为 true。 如果为 false,则生成单个 GeoTIFF,并且所有波段级转换都会被忽略。请注意,如果格式为“ZIPPED_GEO_TIFF”或“ZIPPED_GEO_TIFF_PER_BAND”,则忽略此参数。
format: 下载格式。以下值之一:
  • “ZIPPED_GEO_TIFF”(采用 ZIP 文件封装的 GeoTIFF 文件,默认)
  • “ZIPPED_GEO_TIFF_PER_BAND”(多个 GeoTIFF 文件封装在一个 ZIP 文件中)
  • “NPY”(NumPy 二进制格式)
如果为“GEO_TIFF”或“NPY”,则会忽略 filePerBand 和所有波段级转换。加载 NumPy 输出会生成结构化数组。
id: 已弃用,请改用 image 参数。
callback函数(可选)可选的回调。如果未提供,则以同步方式进行调用。

示例

代码编辑器 (JavaScript)

// A Sentinel-2 surface reflectance image.
var img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');

// A small region within the image.
var region = ee.Geometry.BBox(-122.0859, 37.0436, -122.0626, 37.0586);

var downloadId = ee.data.getDownloadId({
    image: img,
    name: 'single_band',
    bands: ['B3', 'B8', 'B11'],
    region: region
});
print('Single-band GeoTIFF files wrapped in a zip file',
      ee.data.makeDownloadUrl(downloadId));

var downloadId = ee.data.getDownloadId({
  image: img,
  name: 'multi_band',
  bands: ['B3', 'B8', 'B11'],
  region: region,
  scale: 20,
  filePerBand: false
});
print('Multi-band GeoTIFF file wrapped in a zip file',
      ee.data.makeDownloadUrl(downloadId));

var downloadId = ee.data.getDownloadId({
  image: img,
  name: 'custom_single_band',
  bands: [
    {id: 'B3', scale: 10},
    {id: 'B8', scale: 10},
    {id: 'B11', scale: 20}
  ],
  region: region
});
print('Band-specific transformations',
      ee.data.makeDownloadUrl(downloadId));

var downloadId = ee.data.getDownloadId({
  image: img,
  bands: ['B3', 'B8', 'B11'],
  region: region,
  scale: 20,
  format: 'GEO_TIFF'
});
print('Multi-band GeoTIFF file',
      ee.data.makeDownloadUrl(downloadId));

Python 设置

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

import ee
import geemap.core as geemap

Colab (Python)

"""Demonstrates the ee.data.getDownloadId method."""

import io
import requests
import ee


ee.Authenticate()
ee.Initialize()

# A Sentinel-2 surface reflectance image.
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')

# A small region within the image.
region = ee.Geometry.BBox(-122.0859, 37.0436, -122.0626, 37.0586)

# Image chunk as a NumPy structured array.
import numpy
download_id = ee.data.getDownloadId({
    'image': img,
    'bands': ['B3', 'B8', 'B11'],
    'region': region,
    'scale': 20,
    'format': 'NPY'
})
response = requests.get(ee.data.makeDownloadUrl(download_id))
data = numpy.load(io.BytesIO(response.content))
print(data)
print(data.dtype)

# Single-band GeoTIFF files wrapped in a zip file.
download_id = ee.data.getDownloadId({
    'image': img,
    'name': 'single_band',
    'bands': ['B3', 'B8', 'B11'],
    'region': region
})
response = requests.get(ee.data.makeDownloadUrl(download_id))
with open('single_band.zip', 'wb') as fd:
  fd.write(response.content)

# Multi-band GeoTIFF file wrapped in a zip file.
download_id = ee.data.getDownloadId({
    'image': img,
    'name': 'multi_band',
    'bands': ['B3', 'B8', 'B11'],
    'region': region,
    'scale': 20,
    'filePerBand': False
})
response = requests.get(ee.data.makeDownloadUrl(download_id))
with open('multi_band.zip', 'wb') as fd:
  fd.write(response.content)

# Band-specific transformations.
download_id = ee.data.getDownloadId({
    'image': img,
    'name': 'custom_single_band',
    'bands': [
        {'id': 'B3', 'scale': 10},
        {'id': 'B8', 'scale': 10},
        {'id': 'B11', 'scale': 20}
    ],
    'region': region
})
response = requests.get(ee.data.makeDownloadUrl(download_id))
with open('custom_single_band.zip', 'wb') as fd:
  fd.write(response.content)

# Multi-band GeoTIFF file.
download_id = ee.data.getDownloadId({
    'image': img,
    'bands': ['B3', 'B8', 'B11'],
    'region': region,
    'scale': 20,
    'format': 'GEO_TIFF'
})
response = requests.get(ee.data.makeDownloadUrl(download_id))
with open('multi_band.tif', 'wb') as fd:
  fd.write(response.content)