公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
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”(多个 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)
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eee.data.getDownloadId\u003c/code\u003e generates a unique ID and token for downloading Earth Engine data, essential for initiating downloads.\u003c/p\u003e\n"],["\u003cp\u003eIt accepts parameters like image, bands, region, and format to customize the download request to user specifications.\u003c/p\u003e\n"],["\u003cp\u003eUsers can specify download formats including zipped GeoTIFFs (single or multi-band), NumPy arrays, and uncompressed GeoTIFFs.\u003c/p\u003e\n"],["\u003cp\u003eThe function provides flexibility by allowing band-specific transformations such as scale and projection settings for individual bands.\u003c/p\u003e\n"],["\u003cp\u003eDownload links are created using the generated download ID with \u003ccode\u003eee.data.makeDownloadUrl\u003c/code\u003e for accessing the requested data.\u003c/p\u003e\n"]]],["The `ee.data.getDownloadId` function generates a download ID and token for Earth Engine data. Key actions include specifying download parameters like image, bands, region, scale, and format in a `params` object. This can include band-specific transformations. The function returns a `DownloadId`, or null if a callback is specified, allowing for synchronous or asynchronous calls. The output can be configured to be a single or multiple GeoTIFF files wrapped in a zip or in NPY format.\n"],null,[]]