匯出資料表和向量資料

您可以使用 Export.tableFeatureCollection 匯出為 CSV、SHP (形狀檔案)、GeoJSON、KML、KMZ 或 TFRecord。FeatureCollection 可能代表向量,也可能只是資料表。在後一種情況下,集合中的地圖項目會具有空值幾何圖形。

使用某些檔案格式時,請注意以下額外限制:

  • KML:匯出至 KML 檔案的 FeatureCollection 會將所有幾何圖形轉換為未投影 (WGS84) 座標。
  • SHP:匯出至 Shapefile 的 FeatureCollection 必須包含具有相同幾何類型和投影的要素,且必須符合 Shapefile 大小限制。系統會將欄名稱截斷為 10 個字元以下,且不得建立重複的欄名稱。
  • TFRecord:請參閱這個頁面

至 Cloud Storage

如要將 FeatureCollection 匯出至 Cloud Storage,請使用 Export.table.toCloudStorage()。例如,使用先前定義的 features

程式碼編輯器 (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'
});

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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()

到「資產」

如要將 FeatureCollection 匯出為 Earth Engine 資產,請使用 Export.table.toAsset()。例如,使用先前定義的 features

程式碼編輯器 (JavaScript)

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

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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()

Earth Engine 表格資產的大小和形狀有幾項限制:

  • 最多 1 億個地圖項目
  • 最多 1,000 個屬性 (欄)
  • 每個資料列的幾何圖形頂點數量上限為 100,000 個
  • 每個字串值最多 100,000 個半形字元

至 BigQuery

您可以使用 Export.table.toBigQuery()FeatureCollection 匯出至 BigQuery 資料表。這樣一來,您就能將 Earth Engine 資料與 BigQuery 中提供的其他資料和工具整合。詳情請參閱匯出至 BigQuery 指南

程式碼編輯器 (JavaScript)

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

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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()

至雲端硬碟

如要將 FeatureCollection 匯出至雲端硬碟帳戶,請使用 Export.table.toDrive()。例如:

程式碼編輯器 (JavaScript)

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

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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()

請注意,輸出格式已指定為 KML,以便處理地理資料 (SHP 也適合匯出含有幾何圖形的表格)。如要只匯出資料表格而沒有任何地理資訊,請以 CSV 格式匯出具有空值幾何圖形的特徵。以下示範如何使用 Export.table.toDrive() 取得可能長時間執行的縮減作業結果:

程式碼編輯器 (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'
});

Python 設定

請參閱「 Python 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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()

請注意,由於輸出內容中沒有幾何圖形,因此這個範例中的格式設為「CSV」。