askvity

How do I export an image from Google Earth Engine code?

Published in Earth Engine Export 4 mins read

To export an image from Google Earth Engine, you'll typically use the Export functions within the Earth Engine API. Specifically, to export an image to your Earth Engine asset folder, you'll use Export.image.toAsset(). Here's a breakdown of the process and options:

Exporting to your Google Earth Engine Assets

This is the most common way to save an image generated from your Earth Engine code. Assets are stored in your personal or organizational Earth Engine account.

// Assuming 'image' is the ee.Image you want to export
Export.image.toAsset({
  image: image,
  description: 'My_Exported_Image', // A descriptive name for the export task
  assetId: 'users/your_username/My_Exported_Image', // Path to your desired asset location
  scale: 30,          // Pixel resolution in meters (e.g., 30 for Landsat)
  maxPixels: 1e13,   // Maximum number of pixels to process
  region: geometry    // ee.Geometry object defining the area to export
});
  • image: The ee.Image object that you want to export.
  • description: A descriptive name for the export task. This will appear in the Earth Engine Task Manager.
  • assetId: The full path to where you want to save the image in your Earth Engine assets. This should start with users/your_username/ (or projects/your_project/ for shared projects).
  • scale: The pixel resolution (in meters) of the output image. Choose an appropriate scale for your data.
  • maxPixels: The maximum number of pixels to process during the export. Increase this value if you encounter "Too many pixels" errors.
  • region: A ee.Geometry object (e.g., ee.Geometry.Rectangle, ee.Geometry.Polygon) that defines the spatial extent of the image to be exported. This limits the area of the image that gets exported.

Important Considerations for Exporting to Assets:

  • Asset Management: Keep your assets organized by creating folders within your Earth Engine account. Use the Asset Manager in the Earth Engine Code Editor to manage and inspect your assets.
  • Storage Quota: Be aware of your Earth Engine storage quota. The Asset Manager also shows your current usage.
  • Naming Conventions: Use descriptive and consistent naming conventions for your assets.

Exporting to Google Cloud Storage

You can also export images directly to a Google Cloud Storage bucket if you have one configured.

Export.image.toCloudStorage({
  image: image,
  description: 'My_Cloud_Export',
  bucket: 'your-cloud-storage-bucket-name',
  fileNamePrefix: 'My_Image',
  scale: 30,
  maxPixels: 1e13,
  region: geometry
});
  • bucket: The name of your Google Cloud Storage bucket.
  • fileNamePrefix: A prefix that will be added to the filename of the exported image.

Exporting to Google Drive (Not recommended for large images)

While possible, exporting directly to Google Drive is generally not recommended for large images due to potential limitations.

Export.image.toDrive({
  image: image,
  description: 'My_Drive_Export',
  folder: 'EarthEngineExports',  // Optional:  Name of the folder in Google Drive
  fileNamePrefix: 'My_Image',
  scale: 30,
  maxPixels: 1e13,
  region: geometry
});
  • folder: (Optional) The name of the folder in your Google Drive where the image will be saved. If the folder doesn't exist, it will be created.

Initiating the Export Task

In all cases, the Export functions create a task that needs to be started manually in the Earth Engine Code Editor. After running the Export code, go to the "Tasks" tab in the Code Editor and click "Run" next to the task you want to execute. You can monitor the progress of the export in the Task Manager.

Related Articles