Batch download Landsat data from USGS

Data Source

https://earthexplorer.usgs.gov/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
# Python version 3.X
import landsatxplore.api
from landsatxplore.earthexplorer import EarthExplorer

def request_Landsat(username,password,product,bbox,start_date,end_date,cloud_max):
api = landsatxplore.api.API(username, password)
scenes = api.search(
dataset=product,
# latitude=lat,
# longitude=lon,
bbox=bbox,
start_date=start_date,
end_date=end_date,
max_cloud_cover=cloud_max)
print('{} data queried.'.format(len(scenes)))
api.logout()
return scenes

def download_landsat(username,password,Landsat_name,output_dir):
Earth_Down = EarthExplorer(username, password)
for scene in Landsat_name:
ID = scene['entityId']
print('Downloading %s '% ID)
Earth_Down.download(scene_id=ID, output_dir=output_dir)
Earth_Down.logout()


if __name__ == '__main__':
# Your USGS account
username = ''
password = ''
# Select data according to sensor type
product = 'LANDSAT_TM_C1' # Landsat 4、5
# product = 'LANDSAT_ETM_C1' # Landsat 7
# product = 'LANDSAT_8_C1' # Landsat 8
# lat =
# lon =
# The Image Coverage (xmin、ymin、xmax、ymax)
bbox = [34, 119, 35, 120]
start_date='1999-01-01'
end_date='2000-01-01'
# Maximum cloud coverage
cloud_max = 10
# Save path
output_dir = 'E:\\LandsatImg\\'
Landsat_name = request_Landsat(username,password,product,bbox,start_date,end_date,cloud_max)
download_landsat(username,password,Landsat_name,output_dir)