Earth Engine から画像を GeoTIFF 形式または TFRecord 形式でエクスポートできます。その他の出力オプションについては、構成パラメータをご覧ください。
セットアップ例
まず、エクスポートする画像データを定義します。
コードエディタ(JavaScript)
// Load a landsat image and select three bands. var landsat = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_123032_20140515') .select(['B4', 'B3', 'B2']); // Create a geometry representing an export region. var geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236]);
import ee import geemap.core as geemap
Colab(Python)
# Load a landsat image and select three bands. landsat = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_123032_20140515').select( ['B4', 'B3', 'B2'] ) # Create a geometry representing an export region. geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])
次に、以降のエクスポートで使用される projection パラメータを定義します。crs パラメータを使用して座標系を指定し、crsTransform パラメータを使用してピクセル グリッドを正確に指定します。crsTransform パラメータは、アフィン変換行列のパラメータのリストです(行優先順 [xScale, xShearing, xTranslation, yShearing, yScale, yTranslation])。画像の原点は xTranslation と yTranslation の値で定義され、画像のピクセルサイズは xScale と yScale の値で定義されます。アフィン行列の例をご覧ください。
コードエディタ(JavaScript)
// Retrieve the projection information from a band of the original image. // Call getInfo() on the projection to request a client-side object containing // the crs and transform information needed for the client-side Export function. var projection = landsat.select('B2').projection().getInfo();
import ee import geemap.core as geemap
Colab(Python)
# Retrieve the projection information from a band of the original image. # Call getInfo() on the projection to request a client-side object containing # the crs and transform information needed for the client-side Export function. projection = landsat.select('B2').projection().getInfo()
scale を設定する
ショートカットとして、scale パラメータを指定すると、Earth Engine が crsTransform パラメータを計算します。ただし、画像のスケールを設定するだけでは、投影の原点が指定されず、同じピクセルサイズの別の画像に対して画像がシフトする可能性があります。
潜在的なシフトが発生する理由は、scale パラメータを使用して crsTransform の xScale 値と yScale 値が設定される一方で、xTranslation 値と yTranslation 値は、対応する xScale 値と yScale 値で割った余りがゼロになるように計算されるためです。これらのパラメータは、投影の原点がピクセルの隅にあるピクセル グリッドを指定します。この規則は、一部のデータ プロバイダで使用される変換パラメータとは異なります。これらのパラメータでは、投影の原点からオフセットされたグリッドが使用されます。たとえば、USGS が提供する Landsat 画像では、投影の原点から 1/2 ピクセル(30 m バンドの場合は 15 m オフセット)オフセットされた変換パラメータが使用されます。一方、ESA が提供する Sentinel-2 画像では、投影の原点に揃えられた変換パラメータが使用されます。エクスポートで指定された crsTransform が元の画像の crsTransform と一致しない場合、出力ピクセルは再サンプリングされます(デフォルトでは最近傍を使用)。これにより、結果の画像は元の画像に対してシフトされます。
要約すると、エクスポートされた画像のピクセルを特定の画像に一致させる必要がある場合は、crs パラメータと crsTransform パラメータを使用してグリッドを完全に制御してください。
に保存
画像をドライブ アカウントにエクスポートするには、Export.image.toDrive() を使用します。たとえば、Landsat 画像の一部をエクスポートするには、エクスポートするリージョンを定義してから、Export.image.toDrive() を呼び出します。
コードエディタ(JavaScript)
// Export the image, specifying the CRS, transform, and region. Export.image.toDrive({ image: landsat, description: 'imageToDriveExample_transform', crs: projection.crs, crsTransform: projection.transform, region: geometry });
import ee import geemap.core as geemap
Colab(Python)
# Export the image, specifying the CRS, transform, and region. task = ee.batch.Export.image.toDrive( image=landsat, description='imageToDriveExample_transform', crs=projection['crs'], crsTransform=projection['transform'], region=geometry, ) task.start()
このコードを実行すると、コードエディタの [Tasks] タブにエクスポート タスクが作成されます。タスクの横にある [実行] ボタンをクリックして、タスクを開始します。(タスク マネージャーの詳細については、コードエディタのセクションをご覧ください)。画像は、指定された fileFormat でドライブ アカウントに作成されます。
Cloud Storage に
イメージを Google Cloud Storage バケットにエクスポートするには、Export.image.toCloudStorage() を使用します。前の例の Landsat 画像をドライブではなく Cloud Storage にエクスポートするには、次のようにします。
コードエディタ(JavaScript)
// Export the image to Cloud Storage. Export.image.toCloudStorage({ image: landsat, description: 'imageToCloudExample', bucket: 'your-bucket-name', fileNamePrefix: 'exampleExport', crs: projection.crs, crsTransform: projection.transform, region: geometry });
import ee import geemap.core as geemap
Colab(Python)
# Export the image to Cloud Storage. task = ee.batch.Export.image.toCloudStorage( image=landsat, description='imageToCloudExample', bucket='your-bucket-name', fileNamePrefix='exampleExport', crs=projection['crs'], crsTransform=projection['transform'], region=geometry, ) task.start()
ドライブへのエクスポートと同様に、[タスク] タブからエクスポートを開始します。Cloud Storage バケットのロケーションは、パフォーマンスとストレージ費用に影響する可能性があります。詳細については、ロケーションに関する考慮事項に関する FAQ エントリをご覧ください。
アセットに
画像を Earth Engine アセット フォルダ内のアセットにエクスポートするには、Export.image.toAsset() を使用します。Earth Engine アセットを管理したり、保存容量の使用量を確認したりするには、アセット マネージャーを使用します。次の例は、同じバンドに対して異なるピラミッド ポリシーを使用して、Landsat 画像の一部をエクスポートする方法を示しています。ピラミッド化ポリシーは、Earth Engine がアセットの低解像度バージョンを計算する方法を示します。Earth Engine で複数の解像度を処理する方法については、スケールドキュメントをご覧ください。
コードエディタ(JavaScript)
// Get band 4 from the Landsat image, copy it. var band4 = landsat.select('B4').rename('b4_mean') .addBands(landsat.select('B4').rename('b4_sample')) .addBands(landsat.select('B4').rename('b4_max')); // Export the image to an Earth Engine asset. Export.image.toAsset({ image: band4, description: 'imageToAssetExample', assetId: 'exampleExport', crs: projection.crs, crsTransform: projection.transform, region: geometry, pyramidingPolicy: { 'b4_mean': 'mean', 'b4_sample': 'sample', 'b4_max': 'max' } });
import ee import geemap.core as geemap
Colab(Python)
# Get band 4 from the Landsat image, copy it. band_4 = ( landsat.select('B4') .rename('b4_mean') .addBands(landsat.select('B4').rename('b4_sample')) .addBands(landsat.select('B4').rename('b4_max')) ) # Export the image to an Earth Engine asset. task = ee.batch.Export.image.toAsset( image=band_4, description='imageToAssetExample', assetId='projects/your-project/assets/exampleExport', crs=projection['crs'], crsTransform=projection['transform'], region=geometry, pyramidingPolicy={ 'b4_mean': 'mean', 'b4_sample': 'sample', 'b4_max': 'max', }, ) task.start()
'.default' キーを使用して、明示的に指定されていないすべてのバンドにデフォルトのピラミッド化ポリシーを指定できます。'.default' キーのみを渡すこともできます。たとえば、すべてのバンドをデフォルトで「sample」ピラミッド ポリシーにするには、{'.default': 'sample'} を使用します。
構成パラメータ
Export.image に渡される構成パラメータの辞書には、scale(メートル単位)とエクスポート リージョンが ee.Geometry として含まれています。エクスポートされた画像は、指定されたリージョンを指定されたスケールのピクセルでカバーします。明示的に指定されていない場合、出力の CRS は、エクスポートされる画像の最初のバンドから取得されます。
エクスポートされた画像の dimensions、crs、crsTransform を指定することもできます。crs と crsTransform の詳細については、用語集をご覧ください。たとえば、別のデータソースに正確に揃えられたピクセル ブロックを取得するには、dimensions、crs、crsTransform を指定します。領域をカバーする事前定義されたサイズ(256x256 のサムネイル画像など)のピクセル ブロックを取得するには、dimensions と region を指定します。
fileFormat パラメータ(デフォルトは 'GeoTIFF')を使用して、画像出力形式(宛先が toAsset() でない場合)を指定できます。
formatOptions パラメータ
その他の構成オプションは formatOptions パラメータで設定します。このパラメータは、以下で説明するように、各 fileFormat に固有の他の形式オプションをキーとする辞書にする必要があります。
GeoTIFF
クラウド用に最適化された GeoTIFF
クラウドに最適化された GeoTIFF をエクスポートするには、formatOptions の JavaScript リテラルを渡します。このリテラルでは、cloudOptimized キーが true に設定されています。前の例の続き:
コードエディタ(JavaScript)
// Export a cloud-optimized GeoTIFF. Export.image.toDrive({ image: landsat, description: 'imageToCOGeoTiffExample', crs: projection.crs, crsTransform: projection.transform, region: geometry, fileFormat: 'GeoTIFF', formatOptions: { cloudOptimized: true } });
import ee import geemap.core as geemap
Colab(Python)
# Export a cloud-optimized GeoTIFF. task = ee.batch.Export.image.toDrive( image=landsat, description='imageToCOGeoTiffExample', crs=projection['crs'], crsTransform=projection['transform'], region=geometry, fileFormat='GeoTIFF', formatOptions={'cloudOptimized': True}, ) task.start()
クラウドに最適化された GeoTIFF は、Cloud Storage から Image に再読み込みするか、アセットとして登録できます。エクスポートの仕様とオプションの詳細については、Cloud Optimized GeoTIFF(COG)の概要をご覧ください。
Nodata
formatOptions パラメータ内の noData キーを使用して、GeoTIFF の nodata 値を指定します。次に例を示します。
コードエディタ(JavaScript)
// Set a nodata value and replace masked pixels around the image edge with it. var noDataVal = -9999; landsat = landsat.unmask(noDataVal); Export.image.toDrive({ image: landsat, description: 'imageNoDataExample', crs: projection.crs, scale: 2000, // large scale for minimal demo region: landsat.geometry(), // full image bounds fileFormat: 'GeoTIFF', formatOptions: { noData: noDataVal, } });
import ee import geemap.core as geemap
Colab(Python)
# Set a nodata value and replace masked pixels around the image edge with it. no_data_val = -9999 landsat = landsat.unmask(no_data_val) task = ee.batch.Export.image.toDrive( image=landsat, description='imageNoDataExample', crs=projection['crs'], scale=2000, # large scale for minimal demo region=landsat.geometry(), # full image bounds fileFormat='GeoTIFF', formatOptions={'noData': no_data_val}, ) task.start()
nodata 値は、画像の PixelType の有効な範囲内にある必要があります。PixelType は、画像メタデータを印刷し、最初のバンドの data_type プロパティを確認することで確認できます。たとえば、イメージ メソッド toShort() または toInt() を使用してデータを特定の型にキャストすることで、イメージの PixelType を設定することもできます。
TFRecord
TFRecord データ形式のページをご覧ください。
maxPixels
maxPixels パラメータは、非常に大きなエクスポートが誤って作成されるのを防ぐことを目的としています。デフォルト値が目的の出力画像に対して小さすぎる場合は、maxPixels を大きくします。次に例を示します。
Export.image.toDrive({ image: landsat, description: 'maxPixelsExample', crs: projection.crs, crsTransform: projection.transform, region: geometry, maxPixels: 1e9 });
大きなファイルのエクスポート
出力画像が大きい場合は、複数のファイルとしてエクスポートされます。GeoTIFF にエクスポートする場合、画像はタイルに分割されます。各タイルのファイル名は baseFilename-yMin-xMin の形式になります。ここで、xMin と yMin は、エクスポートされた画像の全体的な境界ボックス内の各タイルの座標です。
TFRecord にエクスポートする場合、ファイルには -00000、-00001、... -0000N が付加されます(N+1 個のファイルの場合)。ファイルに対して推論を実行し、予測を画像として Earth Engine にアップロードする場合は、この順序を維持することが重要です。詳細については、画像を TFRecord ファイルとしてアップロードするをご覧ください。
コードエディタに表示されている画像をエクスポートする
Earth Engine で画面にレンダリングされた画像をエクスポートするには、可視化画像と合成とモザイク処理のセクションで説明されているように、可視化画像を作成します。コードエディタは 'EPSG:3857' CRS を使用するため、エクスポートで 'EPSG:3857' の CRS を指定して、コードエディタの地図に表示されるものと同じ投影法の画像を取得します。出力の解像度と座標系を指定する方法については、画像エクスポートの構成に関するセクションをご覧ください。