2

I'm producing a ge image using this code:

image = ee.ImageCollection(satellite) \
            .filterDate(startdate, enddate) \
            .filterBounds(ee.Geometry.Point(centroid[0], centroid[1])) \
            .select(bands) \
            .map(removeClouds) \
            .mean()
type(image)

<class 'ee.image.Image'>

How can I save the resulting image as a local GeoTIFF file, that is, a file stored in the desktop machine that's running the script?

Mauro Assis
  • 375
  • 1
  • 5
  • 22

2 Answers2

3

Not sure about ImageCollection, but you can download an Image to your local drive with:

import requests
import ee

img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')
region = ee.Geometry.BBox(-122.0859, 37.0436, -122.0626, 37.0586)

# Multi-band GeoTIFF file.
url = img.getDownloadUrl({
    'bands': ['B3', 'B8', 'B11'],
    'region': region,
    'scale': 20,
    'format': 'GEO_TIFF'
})
response = requests.get(url)
with open('multi_band.tif', 'wb') as fd:
  fd.write(response.content)

Source: https://developers.google.com/earth-engine/apidocs/ee-image-getdownloadurl#colab-python

Skrt
  • 85
  • 6
2

You cannot download it directly to your local directory. As explained here, "Because Google Earth Engine data exports are asyncronous, the destinations are also cloud-based. Your options are Google Drive, Google Cloud Storage, or new assets in Earth Engine."

For extracting images from Google Drive, this answer can help you.

ablmmcu
  • 161
  • 1
  • 15
  • It seems to me that this link doesn't show to download an image. I would like to download it to my local HD. It shows how to export it to Drive, mas not how to download it after that. I could find another way to download it, but I don't know how can I get the corresponding file ID. – Mauro Assis Apr 28 '22 at 13:50
  • As I said before, you cannot directly download the images to your local HD. First, you should extract images to drive, cloud, or local drive on Earth Engine(I mean as a new asset in EE) then, you can download the collection of images to your local HD. You can find further information here, https://developers.google.com/earth-engine/guides/exporting – ablmmcu Apr 29 '22 at 06:17