哨兵卫星数据-python下载

2021-11-07  本文已影响0人  邯山之郸

代码如下:



# coding: utf-8
from sentinelsat.sentinel import SentinelAPI, read_geojson, geojson_to_wkt
import logging
import os, sys


def download_sentinel_data(user_name,password,website,foot_print,start_date,end_date,platformname,producttype,max_cloud):
    # Sentinel 1 & 2
    api = SentinelAPI(user_name,password,website)
    # print(dir(api))
    # abc = read_geojson(foot_print)
    # footprint = geojson_to_wkt(abc)
    footprint = foot_print
    products = api.query(footprint,
                     date=(start_date, end_date),
                     platformname=platformname,
                     producttype =producttype,
                    cloudcoverpercentage = (0, max_cloud))
    print("PRODUCT SIZE: "+ str(api.get_products_size(products)))
    print("len:",len(products))
    for product in products:
        product_info = api.get_product_odata(product)
        print(product_info)
        print(product_info['title'])
        if product_info['Online']:
            api.download(product)




def download_sentinel_data_3(user_name,password,website,foot_print,start_date,end_date,platformname,producttype,max_cloud):
    # sentinel 3
    api = SentinelAPI(user_name,password,website)
    footprint = geojson_to_wkt(read_geojson(foot_print))
    products = api.query(footprint, date=(start_date,end_date),platformname = platformname,cloudcoverpercentage = max_cloud,producttype= producttype)
    print("PRODUCT SIZE: "+ str(api.get_products_size(products)))

    fp=api.to_geojson(products)
    # print(fp)

    for entry in fp["features"]:

        product_id= entry["properties"]["id"]
        print (entry["properties"]["identifier"])
        print (entry["properties"]["id"])
        print (entry["properties"]["beginposition"])

    api.download(product_id)
    sys.exit()

if __name__ == '__main__':
    os.chdir(r"D:\data")
    user_name = 'xxxxxx'
    password = '********'
    website = 'https://scihub.copernicus.eu/dhus/'
    foot_print = 'POLYGON ((34.322010 0.401648,36.540989 0.876987,36.884121 -0.747357,34.664474 -1.227940,34.322010 0.401648))'
    start_date = '20200122'
    end_date = '20211024'
    platformname = 'Sentinel-2'
    producttype = 'S2MSI2A'
    max_cloud = 60

    download_sentinel_data(user_name,password,website,foot_print,start_date,end_date,platformname,producttype,max_cloud)
上一篇下一篇

猜你喜欢

热点阅读