调用sentinelAPI,输入.shp文件,查询覆盖shp的影像并下载

from sentinelsat.sentinel import SentinelAPI
import ogr
#两个路径都能用
# api = SentinelAPI('*', '*', 'https://scihub.copernicus.eu/apihub/')
api = SentinelAPI('*', '*', 'https://scihub.copernicus.eu/dhus')
download_path=r"*******"
shp_path=r"****.shp"
shp=ogr.Open(shp_path)
layer=shp.GetLayer()
feature=layer.GetNextFeature()
geometry=feature.geometry()
minX,maxX,minY,maxY=geometry.GetEnvelope()
#绘制外接矩形
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(minX, minY)
ring.AddPoint(maxX, minY)
ring.AddPoint(maxX, maxY)
ring.AddPoint(minX, maxY)
ring.AddPoint(minX, minY)
poly = ogr.Geometry(ogr.wkbPolygon)
poly.AddGeometry(ring)
footprint = poly.ExportToWkt()
# print(footprint)
# 定义影像起止时间、数据级别、云量
products = api.query(area=footprint, date=('20190401', '20190501'), platformname='Sentinel-2', producttype='S2MSI1C',cloudcoverpercentage=(0,10))
# 下载影像
for product in products:
    product_info = api.get_product_odata(product)
    if product_info['Online']:  # 下载可在线下载产品
        print(str(i),'/',str(len(products)),product_info['title'])#打印产品文件名
        api.download(product, directory_path=download_path)
        # python
      
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

  • 浏览量 1274
  • 收藏 0
  • 0

所有评论(0)