Xuất dữ liệu vectơ và bảng

Bạn có thể xuất FeatureCollection dưới dạng CSV, SHP (tệp shape), GeoJSON, KML, KMZ hoặc TFRecord bằng Export.table. FeatureCollection có thể đại diện cho các vectơ hoặc chỉ đơn giản là một bảng dữ liệu. Trong trường hợp sau, các đặc điểm trong tập hợp sẽ có hình học rỗng.

Lưu ý một số quy tắc ràng buộc khác khi xử lý một số định dạng tệp, bao gồm:

  • KML: FeatureCollection được xuất sang tệp KML sẽ có tất cả các hình học được chuyển đổi thành toạ độ không chiếu (WGS84).
  • SHP: FeatureCollection được xuất sang tệp Shapefile phải chứa các đối tượng có cùng loại hình học và phép chiếu, đồng thời phải nằm trong giới hạn kích thước tệp Shapefile. Tên cột được cắt bớt còn 10 ký tự trở xuống và không được tạo tên cột trùng lặp.
  • TFRecord: Xem trang này.

vào Cloud Storage

Để xuất FeatureCollection sang Cloud Storage, hãy sử dụng Export.table.toCloudStorage(). Ví dụ: sử dụng features đã xác định trước đó:

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

// Make a collection of points.
var features = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(30.41, 59.933), {name: 'Voronoi'}),
  ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen'}),
  ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet'})
]);

// Export a KML file to Cloud Storage.
Export.table.toCloudStorage({
  collection: features,
  description:'vectorsToCloudStorageExample',
  bucket: 'your-bucket-name',
  fileNamePrefix: 'exampleTableExport',
  fileFormat: 'KML'
});

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 để phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

# Make a collection of points.
features = ee.FeatureCollection([
    ee.Feature(ee.Geometry.Point(30.41, 59.933), {'name': 'Voronoi'}),
    ee.Feature(ee.Geometry.Point(-73.96, 40.781), {'name': 'Thiessen'}),
    ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {'name': 'Dirichlet'}),
])

# Export a KML file to Cloud Storage.
task = ee.batch.Export.table.toCloudStorage(
    collection=features,
    description='vectorsToCloudStorageExample',
    bucket='your-bucket-name',
    fileNamePrefix='exampleTableExport',
    fileFormat='KML',
)
task.start()

thành phần

Để xuất FeatureCollection dưới dạng tài sản Earth Engine, hãy sử dụng Export.table.toAsset(). Ví dụ: sử dụng features được xác định trước:

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

// Export an ee.FeatureCollection as an Earth Engine asset.
Export.table.toAsset({
  collection: features,
  description:'exportToTableAssetExample',
  assetId: 'exampleAssetId',
});

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 để phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

# Export an ee.FeatureCollection as an Earth Engine asset.
task = ee.batch.Export.table.toAsset(
    collection=features,
    description='exportToTableAssetExample',
    assetId='projects/your-project/assets/exampleAssetId',
)
task.start()

Có một số hạn chế về kích thước và hình dạng của tài sản bảng Earth Engine:

  • Tối đa 100 triệu tính năng
  • Tối đa 1.000 thuộc tính (cột)
  • Tối đa 100.000 đỉnh cho mỗi hình học của hàng
  • Tối đa 100.000 ký tự cho mỗi giá trị chuỗi

vào BigQuery

Bạn có thể xuất FeatureCollection sang bảng BigQuery bằng cách sử dụng Export.table.toBigQuery(). Điều này cho phép bạn tích hợp dữ liệu Earth Engine với các dữ liệu và công cụ khác có trong BigQuery. Để biết thêm thông tin, hãy xem Hướng dẫn xuất sang BigQuery.

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

Export.table.toBigQuery({
  collection: features,
  table: 'myproject.mydataset.mytable',
  description: 'put_my_data_in_bigquery',
  append: true,
  overwrite: false
});

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 để phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

task = ee.batch.Export.table.toBigQuery(
    collection=features,
    table='myproject.mydataset.mytable',
    description='put_my_data_in_bigquery',
    append=True,
    overwrite=False,
)
task.start()

vào Drive

Để xuất FeatureCollection sang tài khoản Drive, hãy sử dụng Export.table.toDrive(). Ví dụ:

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

// Export the FeatureCollection to a KML file.
Export.table.toDrive({
  collection: features,
  description:'vectorsToDriveExample',
  fileFormat: 'KML'
});

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 để phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

# Export the FeatureCollection to a KML file.
task = ee.batch.Export.table.toDrive(
    collection=features, description='vectorsToDriveExample', fileFormat='KML'
)
task.start()

Xin lưu ý rằng định dạng đầu ra được chỉ định là KML để xử lý dữ liệu địa lý (SHP cũng phù hợp để xuất một bảng có hình học). Để chỉ xuất một bảng dữ liệu mà không có thông tin địa lý nào, hãy xuất các đối tượng có hình học rỗng ở định dạng CSV. Phần sau đây minh hoạ cách sử dụng Export.table.toDrive() để nhận kết quả của một quá trình giảm có thể kéo dài:

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

// Load a Landsat image.
var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318');
var projection = image.select('B2').projection().getInfo();

// Create an arbitrary rectangle.
var region = ee.Geometry.Rectangle(-122.2806, 37.1209, -122.0554, 37.2413);

// Get a dictionary of means in the region.
var means = image.reduceRegion({
  reducer: ee.Reducer.mean(),
  geometry: region,
  crs: projection.crs,
  crsTransform: projection.transform,
});

// Make a feature without geometry and set the properties to the dictionary of means.
var feature = ee.Feature(null, means);

// Wrap the Feature in a FeatureCollection for export.
var featureCollection = ee.FeatureCollection([feature]);

// Export the FeatureCollection.
Export.table.toDrive({
  collection: featureCollection,
  description: 'exportTableExample',
  fileFormat: 'CSV'
});

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 để phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

# Load a Landsat image.
image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')
projection = image.select('B2').projection().getInfo()

# Create an arbitrary rectangle.
region = ee.Geometry.Rectangle(-122.2806, 37.1209, -122.0554, 37.2413)

# Get a dictionary of means in the region.
means = image.reduceRegion(
    reducer=ee.Reducer.mean(),
    geometry=region,
    crs=projection['crs'],
    crsTransform=projection['transform'],
)

# Make a feature without geometry and set the properties to the dictionary of means.
feature = ee.Feature(None, means)

# Wrap the Feature in a FeatureCollection for export.
feature_collection = ee.FeatureCollection([feature])

# Export the FeatureCollection.
task = ee.batch.Export.table.toDrive(
    collection=feature_collection,
    description='exportTableExample',
    fileFormat='CSV',
)
task.start()

Lưu ý rằng định dạng được đặt thành "CSV" trong ví dụ này vì không có hình học nào trong kết quả.