下载sentinelhub(python)提供的列表中的所有数据

2024-06-28 20:58:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试一次下载所有查询到的数据。我的代码如下:

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\U操作\U MSI\U L1C\U TL\U EPAE\U 20180307T093658\U A014132\U T37SBD\U N02.06 S2A\U操作\U MSI\U L1C\U TL\U EPAE\U 20180307T093658\U A014132\U T36SYH\U N02.06 S2A\U操作\U MSI\U L1C\U TL\U EPAE\U 20180307T093658\U A014132\U T36SYJ\U N02.06 S2A\U操作\U MSI\U L1C\U TL\U EPAE\U 20180307T093658\U A014132\U T37SBC\U N02.06 S2B\U操作\U MSI\U L1C\U TL\U MPS\U 20180305T103142\U A005195\U T36SYH\U N02.06

在返回这个tile\u id列表后,我使用代码提取tile-`name and date of a single tile\u id(例如:S2B\u OPER\u MSI\u L1C\u TL\u MPS\uu 20170906T122033\u A002621\u T36STA\u 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() 

因此,为了下载几个图像,我必须复制和粘贴瓷砖的id每次。我的问题是:如何编写一个代码,让它先下载一个Tile\u id,然后再下载第二个Tile\u id。一直下载到列表完成。 当做, 本


Tags: 代码nameawsiddataindextimemsi
1条回答
网友
1楼 · 发布于 2024-06-28 20:58:15

为了明确地回答您的问题,您需要使用sentinelhubweb功能服务获得满足您的参数的所有tile的列表。然后您可以通过迭代器传递该列表,提取tile/产品请求的输入信息,并请求他们实现它。你知道吗

这是我的代码,它不是很漂亮,但它做的把戏。请注意,它当前设置为以.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') 

相关问题 更多 >