遙感圖像批量下載


  介紹一下遙感圖像批量下載的方法,主要是針對Landsat和Sentinel數據進行下載。兩種數據在USGS上都能找到,速度比較慢。Sentinel數據還可以在https://scihub.copernicus.eu/上面找到,下載速度很慢,本人下載需要連vpn,否則會報錯。今天主要利用國外友人開發的python包實現下載的目的。

  1. landsatxplore

    兩種調用方式,一是在cmd里面直接查詢並且下載,二是通過python api進行下載。在api中,可以設置點/框來選取search的區域,此外還有產品(TM/ETM/OLI),日期,雲量等等選擇。

import landsatxplore.api
from landsatxplore.earthexplorer import EarthExplorer

def request_Landsat(username,password,product,bbox,start_date,end_date,cloud_max):  #search
#如果設置的是點,那么添加lon\lat變量,去掉bbox
    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('{} scenes found.'.format(len(scenes)))
    api.logout()
    return scenes

def download_landsat(username,password,Landsat_name,output_dir):   #download
    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()

username = '.....'
password = '.....'
product = 'LANDSAT_8_C1'
# lon = 34.020794936018724  #如果用點,那么函數中需要去掉bbox,添加lat\lon
# lat = 120.234375
bbox = [34.361576287484176, 119.9871826171875, 34.610605760914666,  120.201416015625]   #bbox框 [xmin,ymin,xmax,ymax]
start_date = '2014-01-01'
end_date = '2016-01-01'
cloud_max = 10
output_dir = '.\data'
Landsat_name = request_Landsat(username, password, product, location, start_date, end_date, cloud_max)
download_landsat(username, password, Landsat_name, output_dir)

   2. sentinelsat。這個由於request的是另一個網站,下載速度奇慢無比,還有單個賬號的下載數量限制,挺坑的。據說早上起來下載速度會比較快。

from sentinelsat.sentinel import SentinelAPI, read_geojson, geojson_to_wkt
from datetime import date
# connect to the API
api = SentinelAPI('....', '....', 'https://scihub.copernicus.eu/dhus')
footprint = geojson_to_wkt(read_geojson('map.geojson'))   #可以指定經緯度,也可以用geojson格式文件來定義區域范圍,見http://geojson.io
products = api.query(footprint,
                     date=('20101219', '20181210'),
                     platformname='Sentinel-2',
                     cloudcoverpercentage=(0, 30))

print('Search the number of images: '+ str(len(products)))
for product in products:
    product_info = api.get_product_odata(product)
    print(product_info['title'])
    api.download(product, directory_path='./data')  #單次下載
#  api.download_all(products)  全部下載

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM