我正在尝试下载一次查询的所有数据。我的代码如下:
from sentinelhub import AwsProductRequest, AwsTileRequest, AwsTile, BBox, CRS
import sentinelhub
betsiboka_coords_wgs84 = [38.788605,35.781057,39.314575,36.180008]
bbox = BBox(bbox=betsiboka_coords_wgs84, crs=CRS.WGS84)
date= '2016-09-05',('2018-03-08')
for i in data:
print(i['properties']['title'])
此代码返回: S2A_OPER_MSI_L1C_TL_EPAE_20180307T093658_A014132_T37SBD_N02.06 S2A_OPER_MSI_L1C_TL_EPAE_20180307T093658_A014132_T36SYH_N02.06 S2A_OPER_MSI_L1C_TL_EPAE_20180307T093658_A014132_T36SYJ_N02.06 S2A_OPER_MSI_L1C_TL_EPAE_20180307T093658_A014132_T37SBC_N02.06 S2B_OPER_MSI_L1C_TL_MPS__20180305T103142_A005195_T36SYH_N02.06
在返回tile_id列表之后,我使用代码提取单个tile_id的tile-name和日期(例如: S2B_OPER_MSI_L1C_TL_MPS__20170906T122033_A002621_T36STA_N02.05):
tile_id ='S2B_OPER_MSI_L1C_TL_MPS__20170906T122033_A002621_T36STA_N02.05'
tile_name, time, aws_index = AwsTile.tile_id_to_tile(tile_id)
tile_name, time, aws_index
返回: ('36STA','2017-9-6',0)
最后一段代码告诉我们应该下载什么频段,应该下载哪些频段等等:
bands = ['B02','B03','B04']
metafiles = [ 'preview']
data_folder = './ChangeDetection'
request = AwsTileRequest(tile=tile_name, time=time, aws_index=aws_index,
bands=bands, metafiles=metafiles, data_folder=data_folder)
request.save_data()
因此,为了下载多个图像,我每次都要复制并粘贴Tile_id。我的问题是:我如何编写代码,以便它获取一个Tile_id下载,然后转到第二个Tile_id并下载它。并继续下载,直到列表完成。 问候, 本
答案 0 :(得分:0)
要具体回答您的问题,您需要使用Sentinelhub Web功能服务获取符合您的参数的所有图块的列表。然后,您可以通过迭代器传递该列表,为图块/产品提取输入信息,要求他们实现。
这是我所拥有的代码,虽然不是很漂亮,但是可以解决问题。请注意,当前已将其设置为以.SAFE模式下载,并且,如果您不在AWS环境中工作,则需要传递AWS安全凭证。
from sentinelhub import WebFeatureService, BBox, CRS, AwsProductRequest, AwsTile, DataSource, AwsTileRequest
# config for sentinelhub WFS requests
INSTANCE_ID = 'YOUR INSTANCE HERE'
#boundslist format eg = [101.429, 0.4629, 101.64, 0.6737]
#searchdates format eg =('2018-08-01T00:00:00', '2018-08-31T23:59:59')
#cloudmax format eg = 0.25
def batchdownloader(boundslist,searchdates,cloudmax,downloadfolder,):
search_bbox = BBox(bbox = boundslist, crs=CRS.WGS84)
search_time_interval = searchdates
wfs_iterator = WebFeatureService(search_bbox, search_time_interval,
data_source=DataSource.SENTINEL2_L1C,
maxcc=cloudmax, instance_id=INSTANCE_ID)
outinfo=wfs_iterator.get_tiles()
print('The tool will download',len(outinfo), 'images.')
for i in outinfo:
tilename = i[0]
tiledate = i[1]
tileindex = i[2]
productid=(AwsTile(tile_name=tilename, time=tiledate, aws_index=tileindex, data_source=DataSource.SENTINEL2_L1C).get_product_id())
print (productid)
#Uncomment the below code if you want to download the whole product
#product_request = AwsProductRequest(product_id=productid, data_folder=downloadfolder, safe_format=True)
#product_request.save_data()
#print (productid, '.SAFE folder for this image has been downloaded to', downloadfolder, )
#uncomment the below code if you want to download just the tiles
#tile_request = AwsTileRequest(tile=tilename, time=tiledate, aws_index=tileindex, data_folder=downloadfolder, safe_format=True)
#tile_request.save_data()
#print (productid, 'Tiles for this image have been downloaded to', downloadfolder)
i =+1
print('Completed downloads.')
batchdownloader([110.3055, -1.0574, 110.4125, -0.87],('2018-06-15T00:00:00', '2018-06-30T23:59:59'), 0.4, r'C:\YOURFOLDER')