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: :要用于任何未指定比例的波段的默认比例;如果指定了 crs 和 crs_transform,则忽略此参数。
region: :指定要下载的区域的多边形;如果指定了 crs 和 crs_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”(封装在 ZIP 文件中的多个 GeoTIFF 文件)
  • “NPY”(NumPy 二进制格式)
如果为“GEO_TIFF”或“NPY”,则 filePerBand 和所有波段级转换都将被忽略。加载 NumPy 输出会生成结构化数组。
id: 已弃用,请使用图片参数。
callback函数,可选可选回调。如果未提供,则会同步发出调用。

示例

代码编辑器 (JavaScript)

// A Sentinel-2 surface reflectance image.
var img = ee.Image('COPERNICUS/S2_SR_HARMONIZED/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 numpy
import requests

# A Sentinel-2 surface reflectance image.
img = ee.Image('COPERNICUS/S2_SR_HARMONIZED/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.
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))
display(data)
display(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)