利用Python下載Landsat數據

儘管Landsat數據應用廣泛,但是數據下載一直都是比較困難的事情。國內數據一般採用地理空間數據雲或者中科院的網站勉強都可以搞定。但是國外的數據一般很難下載到。這裏面主要存在兩個問題:
1)因爲下載數據的網站經常性連接不上,包括EarthExplore和Glovis。
2)批量數據下載困難。
最近在思考如何更簡單的進行數據的批量下載。下面介紹一下使用方法,代碼依然採用的是Python。下載方式其實非常簡單,主要用到landsatxplore這個庫,這個庫的github地址是https://github.com/yannforget/landsatxplore。裏面有詳細的介紹,我主要介紹一下我的使用心得。使用前,你需要先註冊EarthExplore的賬戶,記住你的username 和 password

安裝:

pip install landsatxplore

用戶登錄:

api = landsatxplore.api.API(username, password)

數據搜索:這裏面我沒換位置,因爲顯然經緯度的點在國外,數據集你可以選擇TM,ETM和Landsat8 (LANDSAT_TM_C1|LANDSAT_ETM_C1|LANDSAT_8_C1),這裏我以Landsat8爲例,設置數據篩選時間,雲量

scenes = api.search(
    dataset='LANDSAT_8_C1',
    latitude=19.53,
    longitude=-1.53,
    start_date='2014-01-01',
    end_date='2016-01-01',
    max_cloud_cover=10)

數據篩選結果:
在這裏插入圖片描述
數據下載:

Earth_Down = EarthExplorer(username, password)
Earth_Down.download(scene_id='LC81960462014022LGN01', output_dir='E:\data')

數據下載結果:
在這裏插入圖片描述
下載速度大概4M/s,速度還可以。目前批量下載沒有問題,就是還不清楚批量下載是網絡連接是不是穩定。
詳細代碼如下:

import landsatxplore.api
from landsatxplore.earthexplorer import EarthExplorer

def request_Landsat(username,password,product,lat,lon,start_date,end_date,cloud_max):

    api = landsatxplore.api.API(username, password)

    scenes = api.search(
        dataset=product,
        latitude=lat,
        longitude=lon,
        start_date=start_date,
        end_date=end_date,
        max_cloud_cover=cloud_max)

    print('{} scenes found.'.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 data %s '% ID)
        Earth_Down.download(scene_id=ID, output_dir=output_dir)

    Earth_Down.logout()

if __name__ == '__main__':

    username = ''
    password = ''
    product = 'LANDSAT_8_C1'
    lat = 19.53
    lon = -1.53
    start_date='2014-01-01'
    end_date='2016-01-01'
    cloud_max = 10
    output_dir = '.\data'
    Landsat_name = request_Landsat(username,password,product,lat,lon,start_date,end_date,cloud_max)
    download_landsat(username,password,Landsat_name,output_dir)

在這裏插入圖片描述
祝好!
2020.01.02

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章