7

I am using Google's Earth Engine API to access LandSat images. The program is as given below,

import ee
ee.Initialize()

Load a landsat image and select three bands.

landsat = ee.Image('LANDSAT/LC8_L1T_TOA
/LC81230322014135LGN00').select(['B4', 'B3', 'B2']);

Create a geometry representing an export region.

geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236]);

Export the image, specifying scale and region.

 export.image.toDrive({
    image: landsat,
    description: 'imageToDriveExample',
    scale: 30,  
    region: geometry
    });

it throws the following error.

Traceback (most recent call last):
File "e6.py", line 11, in <module>
export.image.toDrive({
NameError: name 'export' is not defined

Please Help. I am unable to find the right function to download images.

ArK
  • 20,698
  • 67
  • 109
  • 136
A S
  • 103
  • 1
  • 2
  • 5

5 Answers5

8

If you are using the python API, you have to use the 'batch' submodule. The default behaviour is to save to your google drive. You can specify your bounding box as a list of coordinates as well:

llx = 116.2621
lly = 39.8412
urx = 116.4849
ury = 40.01236
geometry = [[llx,lly], [llx,ury], [urx,ury], [urx,lly]]

task_config = {
    'description': 'imageToDriveExample',
    'scale': 30,  
    'region': geometry
    }

task = ee.batch.Export.image(landsat, 'exportExample', task_config)

task.start()

This should generate a file called 'exportExample.tif' in your GoogleDrive top folder.

Also note that the semicolons at the end of each line are not necessary in python.

Ben DeVries
  • 506
  • 3
  • 6
2

To build on Ben's answer, you can also use:

geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])

from your original post, but add the following line beneath it so the coordinates are in the correct format for the task_config-->Region field:

geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])
geometry = geometry['coordinates'][0]

It prevents a "task_config" formatting mismatch when you get to here:

task = ee.batch.Export.image(landsat, 'exportExample', task_config)

This will allow you to use the given function from the API, but it will extract the coordinates in such a way that you can use them in the approach suggested by Ben above.

Community
  • 1
  • 1
MikeS
  • 21
  • 2
1

There is a typo in your code, Export should start from the capital letter. See documentation.

G07cha
  • 4,009
  • 2
  • 22
  • 39
0

Where do you specify the dates? Is there any good, quick, documentation or tutorial for Python? seems there are plenty about JavaScript one!

OverFlow Police
  • 861
  • 6
  • 23
0

There is good, quick example of python api.You can check this link. There is 1 post for download satellite image using python api.

Ratan gupta
  • 159
  • 2
  • 1
    It may not be a good answer when the link breaks, but for now I found it quite useful, especially for how to download to local drive instead of google drive. – jNorris Apr 14 '20 at 22:46