Export.image.toDrive

Tạo một tác vụ hàng loạt để xuất Hình ảnh dưới dạng một hình ảnh raster sang Drive. Bạn có thể bắt đầu việc cần làm từ thẻ Tasks. "crsTransform", "scale" và "dimensions" là các thuộc tính loại trừ lẫn nhau.

Cách sử dụngGiá trị trả về
Export.image.toDrive(image, description, folder, fileNamePrefix, dimensions, region, scale, crs, crsTransform, maxPixels, shardSize, fileDimensions, skipEmptyTiles, fileFormat, formatOptions, priority)
Đối sốLoạiThông tin chi tiết
imageHình ảnhHình ảnh cần xuất.
descriptionChuỗi, không bắt buộcTên dễ đọc của việc cần làm. Có thể chứa chữ cái, số, dấu gạch ngang, dấu gạch dưới (không có dấu cách). Giá trị mặc định là "myExportImageTask".
folderChuỗi, không bắt buộcThư mục trên Google Drive nơi tệp xuất sẽ được lưu trữ. Lưu ý: (a) nếu tên thư mục tồn tại ở bất kỳ cấp độ nào, đầu ra sẽ được ghi vào đó, (b) nếu có tên thư mục trùng lặp, đầu ra sẽ được ghi vào thư mục được sửa đổi gần đây nhất, (c) nếu tên thư mục không tồn tại, một thư mục mới sẽ được tạo ở thư mục gốc và (d) tên thư mục có dấu phân cách (ví dụ: "path/to/file") được hiểu là chuỗi ký tự chứ không phải đường dẫn hệ thống. Giá trị mặc định là thư mục gốc của Drive.
fileNamePrefixChuỗi, không bắt buộcTiền tố tên tệp. Có thể chứa chữ cái, số, dấu gạch ngang, dấu gạch dưới (không có dấu cách). Giá trị mặc định là nội dung mô tả.
dimensionsNumber|String, không bắt buộcKích thước dùng cho hình ảnh được xuất. Lấy một số nguyên dương duy nhất làm kích thước tối đa hoặc "WIDTHxHEIGHT", trong đó WIDTH và HEIGHT đều là số nguyên dương.
regionGeometry.LinearRing|Geometry.Polygon|String, không bắt buộcLinearRing, Polygon hoặc toạ độ đại diện cho khu vực cần xuất. Bạn có thể chỉ định các đối tượng này dưới dạng đối tượng Hình học hoặc toạ độ được chuyển đổi tuần tự thành một chuỗi.
scaleSố, không bắt buộcĐộ phân giải tính bằng mét trên mỗi pixel. Giá trị mặc định là 1000.
crsChuỗi, không bắt buộcCRS sẽ dùng cho hình ảnh được xuất.
crsTransformList<Number>|String, optionalPhép biến đổi affine dùng cho hình ảnh được xuất. Yêu cầu bạn xác định "crs".
maxPixelsSố, không bắt buộcHạn chế số lượng pixel trong tệp xuất. Theo mặc định, bạn sẽ thấy lỗi nếu dữ liệu xuất vượt quá 100 triệu pixel. Việc đặt giá trị này một cách rõ ràng cho phép bạn tăng hoặc giảm giới hạn này.
shardSizeSố, không bắt buộcKích thước tính bằng pixel của các ô mà hình ảnh này sẽ được tính toán. Giá trị mặc định là 256.
fileDimensionsList<Number>|Number, optionalKích thước (tính bằng pixel) của mỗi tệp hình ảnh, nếu hình ảnh quá lớn để vừa trong một tệp. Có thể chỉ định một số duy nhất để biểu thị hình vuông hoặc một mảng gồm 2 chiều để biểu thị (chiều rộng, chiều cao). Xin lưu ý rằng hình ảnh vẫn sẽ bị cắt theo kích thước tổng thể của hình ảnh. Phải là bội số của shardSize.
skipEmptyTilesBoolean, không bắt buộcNếu là true, hãy bỏ qua việc ghi các ô hình ảnh trống (tức là được che hoàn toàn). Giá trị mặc định là false. Chỉ được hỗ trợ trên các tệp xuất GeoTIFF.
fileFormatChuỗi, không bắt buộcĐịnh dạng tệp chuỗi mà hình ảnh được xuất sang. Hiện tại, chỉ có "GeoTIFF" và "TFRecord" được hỗ trợ, mặc định là "GeoTIFF".
formatOptionsImageExportFormatConfig (không bắt buộc)Từ điển gồm các khoá chuỗi cho các lựa chọn cụ thể theo định dạng. Đối với "GeoTIFF": "cloudOptimized" (Boolean), "noData" (float). Đối với "TFRecord": hãy xem https://developers.google.com/earth-engine/guides/tfrecord#formatoptions
prioritySố, không bắt buộcMức độ ưu tiên của công việc trong dự án. Các công việc có mức độ ưu tiên cao hơn sẽ được lên lịch sớm hơn. Phải là số nguyên từ 0 đến 9999. Giá trị mặc định là 100.

Ví dụ

Trình soạn thảo mã (JavaScript)

// A Landsat 8 surface reflectance image.
var image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508')
  .select(['SR_B.']);  // reflectance bands

// A region of interest.
var region = ee.Geometry.BBox(-122.24, 37.13, -122.11, 37.20);

// Set the export "scale" and "crs" parameters.
Export.image.toDrive({
  image: image,
  description: 'image_export',
  folder: 'ee_demos',
  region: region,
  scale: 30,
  crs: 'EPSG:5070'
});

// Use the "crsTransform" export parameter instead of "scale" for more control
// over the output grid. Here, "crsTransform" is set to align the output grid
// with the grid of another dataset. To view an image's CRS transform:
// print(image.projection())
Export.image.toDrive({
  image: image,
  description: 'image_export_crstransform',
  folder: 'ee_demos',
  region: region,
  crsTransform: [30, 0, -2493045, 0, -30, 3310005],
  crs: 'EPSG:5070'
});

// If the export has more than 1e8 pixels, set "maxPixels" higher.
Export.image.toDrive({
  image: image,
  description: 'image_export_maxpixels',
  folder: 'ee_demos',
  region: region,
  scale: 30,
  crs: 'EPSG:5070',
  maxPixels: 1e13
});

// Export a Cloud Optimized GeoTIFF (COG) by setting the "cloudOptimized"
// parameter to true.
Export.image.toDrive({
  image: image,
  description: 'image_export_cog',
  folder: 'ee_demos',
  region: region,
  scale: 30,
  crs: 'EPSG:5070',
  formatOptions: {
    cloudOptimized: true
  }
});

// Define a nodata value and replace masked pixels with it using "unmask".
// Set the "sameFootprint" parameter as "false" to include pixels outside of the
// image geometry in the unmasking operation.
var noDataVal = -9999;
var unmaskedImage = image.unmask({value: noDataVal, sameFootprint: false});
// Use the "noData" key in the "formatOptions" parameter to set the nodata value
// (GeoTIFF format only).
Export.image.toDrive({
  image: unmaskedImage,
  description: 'image_export_nodata',
  folder: 'ee_demos',
  region: image.geometry(),  // full image bounds
  scale: 2000,  // large scale for minimal demo
  crs: 'EPSG:5070',
  fileFormat: 'GeoTIFF',
  formatOptions: {
    noData: noDataVal
  }
});

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

# A Landsat 8 surface reflectance image.
image = ee.Image(
    'LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508'
).select(['SR_B.'])  # reflectance bands

# A region of interest.
region = ee.Geometry.BBox(-122.24, 37.13, -122.11, 37.20)

# Set the export "scale" and "crs" parameters.
task = ee.batch.Export.image.toDrive(
    image=image,
    description='image_export',
    folder='ee_demos',
    region=region,
    scale=30,
    crs='EPSG:5070'
)
task.start()

# Use the "crsTransform" export parameter instead of "scale" for more control
# over the output grid. Here, "crsTransform" is set to align the output grid
# with the grid of another dataset. To view an image's CRS transform:
# print(image.projection().getInfo())
task = ee.batch.Export.image.toDrive(
    image=image,
    description='image_export_crstransform',
    folder='ee_demos',
    region=region,
    crsTransform=[30, 0, -2493045, 0, -30, 3310005],
    crs='EPSG:5070'
)
task.start()

# If the export has more than 1e8 pixels, set "maxPixels" higher.
task = ee.batch.Export.image.toDrive(
    image=image,
    description='image_export_maxpixels',
    folder='ee_demos',
    region=region,
    scale=30,
    crs='EPSG:5070',
    maxPixels=1e13
)
task.start()

# Export a Cloud Optimized GeoTIFF (COG) by setting the "cloudOptimized"
# parameter to true.
task = ee.batch.Export.image.toDrive(
    image=image,
    description='image_export_cog',
    folder='ee_demos',
    region=region,
    scale=30,
    crs='EPSG:5070',
    formatOptions={
        'cloudOptimized': True
    }
)
task.start()

# Define a nodata value and replace masked pixels with it using "unmask".
# Set the "sameFootprint" parameter as "false" to include pixels outside of the
# image geometry in the unmasking operation.
nodata_val = -9999
unmasked_image = image.unmask(value=nodata_val, sameFootprint=False)
# Use the "noData" key in the "formatOptions" parameter to set the nodata value
# (GeoTIFF format only).
task = ee.batch.Export.image.toDrive(
    image=unmasked_image,
    description='image_export_nodata',
    folder='ee_demos',
    region=image.geometry(),  # full image bounds
    scale=2000,  # large scale for minimal demo
    crs='EPSG:5070',
    fileFormat='GeoTIFF',
    formatOptions={
        'noData': nodata_val
    }
)
task.start()