3

I am trying to export a collection of Landsat images (but at this point I will settle for a single image) from Google Earth Engine to my Google Drive. I am using the Python API from my local terminal but I can not get the Export.image.toDrive (or ee.batch.Export.image.toDrive) to work. I even tried the code in the JavaScript code editor (in JavaScript, not Python) and it didn't work there either.

I have tried everything I can find on Google API Docs, StackOverflow, and GIS StackExchange - nothing has worked for me.

Eventually I need to iterate over an ImageCollection but to keep it simple for initial export here is my code for a single image:

#python
import datetime
import ee
import ee.mapclient

ee.Initialize()

#download a polygon to clip the collection of images down to
okla = (ee.FeatureCollection('TIGER/2018/States') #get oklahoma polygon to filter images by, this polygon is correct
    .filter(ee.Filter().eq('NAME','Oklahoma')))

#download image collection
collection = (ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
             .filterDate(datetime.datetime(2012, 1, 1),
                         datetime.datetime(2012, 1, 30)) #set dates to download (year,month,day)
            .filterBounds(okla)) #this is not a full clip

#condense collection to single image (do not want to do this in the future)
image1 = collection.mean() #takes the average of images in collection

image2 = image1.clipToCollection(okla) #this works and actually clips images to outline of Oklahoma

taskToexport = ee.batch.Export.image.toDrive(
        image = image2,             
        description = 'test1',
        )  

taskToexport.start()
1
  • Note that you can use ee.Date.fromYMD(2012, 1, 1) instead of datetime.datetime(2012, 1, 1). Commented Jan 14, 2020 at 21:43

1 Answer 1

4

Using your script, I ran taskToexport.status() to check on the status of the download request and an error was returned:

error_message: Unable to export unbounded image.

You need to provide an argument to the region parameter of the ee.batch.Export.image.toDrive function to bound the extent of the download:

taskToexport = ee.batch.Export.image.toDrive(
        image = image2,             
        region = okla.geometry().bounds().getInfo()['coordinates'],
        description = 'test1',
        )

taskToexport.start()

The region parameter is described as such:

A LinearRing, Polygon, or coordinates representing region to export. These may be specified as the Geometry objects or coordinates serialized as a string. If not specified, the region defaults to the viewport at the time of invocation.

Note that If not specified, the region defaults to the viewport at the time of invocation, but within the Python API there is no Map viewport, so an error occurs. Within the Python API you should always set the region parameter.

6
  • 1
    Hi Justin, thanks for your suggestion. I added a region parameter to my code but I am still not getting the image in my Google Drive. Also, taskToexport.status() does not return any errors to me, even when I leave out the region parameter. Any ideas?
    – kcook
    Commented Jan 14, 2020 at 22:19
  • I'm not sure why it is not showing up in your Google Drive - try refreshing, sorting by creation date, and using the search bar. Here is the a slightly modified version that uses ee.Date.fromYMD and includes other parameters for the export: gist.github.com/jdbcode/51ae9029b56eaeb2b3fe364e7f9a4f61. Note that when you are checking the status, you'll need to wait a little while and check again periodically for "state" to be "completed". You can also monitor task progress from the Code Editor Task tab (even if task is started from Python) Commented Jan 15, 2020 at 0:12
  • Ok, I see what you mean about the task progress in the Code Editor, that is very helpful. I do not know what changed but I was able to download the image to my Drive this morning. Quick question though, on your end can you open the image and see Oklahoma or anything? When I open my image in Photoshop it is completely black. I guess I expected it to download all of the bands as a different image - just like when you download Landsat images from the USGS.
    – kcook
    Commented Jan 15, 2020 at 15:42
  • The Landsat SR data are int16 data type geotiff, which is maybe not something that Photoshop can read. You can, however, convert the Landsat data into an RGB image that Photoshop should be able to handle. Here is your script with and extra line to .visualize() your image: gist.github.com/jdbcode/ed65cdf096f648f1c3d90922d9cc3e4c. If that does not work, you can also create PNG thumbnail images: developers.google.com/earth-engine/… Commented Jan 15, 2020 at 23:31
  • Thank you so much, I am really new to all this and this has been so helpful!
    – kcook
    Commented Jan 16, 2020 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.