遥感图像批量下载
介绍一下遥感图像批量下载的方法,主要是针对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) 全部下载