ee.Image.getDownloadURL

获取 GeoTIFF 或 NumPy 格式的小块图片数据的下载网址。请求大小上限为 32 MB,网格维度上限为 10000。

针对 RGB 可视化格式 PNG 和 JPG 使用 getThumb网址。

返回下载网址,如果指定了回调,则返回 undefined。

用法返回
Image.getDownloadURL(params, callback)对象|字符串
参数类型详细信息
此:image图片Image 实例。
params对象一个包含下载选项的对象,可用的值如下:
name: 用于构建文件名的基本名称。仅在格式为“ZIPPED_GEO_TIFF”(默认)或 filePerBand 为 true 时适用。如果格式为“ZIPPED_GEO_TIFF”或 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,并且所有波段级转换都会被忽略。
format: 下载格式。以下值之一:
  • “ZIPPED_GEO_TIFF”(封装在 zip 文件中的 GeoTIFF 文件,默认)
  • “GEO_TIFF”(GeoTIFF 文件)
  • “NPY”(NumPy 二进制格式)
如果为“GEO_TIFF”或“NPY”,则会忽略 filePerBand 和所有波段级转换。加载 NumPy 输出会生成结构化数组。
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);

print('Single-band GeoTIFF files wrapped in a zip file',
  img.getDownloadURL({
    name: 'single_band',
    bands: ['B3', 'B8', 'B11'],
    region: region
  }));

print('Multi-band GeoTIFF file wrapped in a zip file',
  img.getDownloadURL({
    name: 'multi_band',
    bands: ['B3', 'B8', 'B11'],
    region: region,
    scale: 20,
    filePerBand: false
  }));

print('Band-specific transformations',
  img.getDownloadURL({
    name: 'custom_single_band',
    bands: [
      {id: 'B3', scale: 10},
      {id: 'B8', scale: 10},
      {id: 'B11', scale: 20}
    ],
    region: region
  }));

print('Multi-band GeoTIFF file',
  img.getDownloadURL({
    bands: ['B3', 'B8', 'B11'],
    region: region,
    scale: 20,
    format: 'GEO_TIFF'
  }));

Python 设置

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

import ee
import geemap.core as geemap

Colab (Python)

"""Demonstrates the ee.Image.getDownloadURL 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
url = img.getDownloadUrl({
    'bands': ['B3', 'B8', 'B11'],
    'region': region,
    'scale': 20,
    'format': 'NPY'
})
response = requests.get(url)
data = numpy.load(io.BytesIO(response.content))
print(data)
print(data.dtype)

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

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

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

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