eodags1.py 1.69 KB
Newer Older
Lozac'h Loic's avatar
Lozac'h Loic committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'''
Created on 18 juin 2021

@author: loic
'''
import os
from eodag.utils.logging import setup_logging
from eodag.api.core import EODataAccessGateway
from frozenapp.models import TileEnvelope


class EodagS1Downloader():
    '''
    classdocs
    '''
    
    mEODataAccessGateway = None
    user_conf_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"eodag/user_conf.yml")
    locations_conf_path = None
    providers_conf_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"eodag/providers.yml")


    def __init__(self, mrgstile, startdate, enddate):
        '''
        Constructor
        '''
        
        qs_tile =  TileEnvelope.objects.filter(tile__exact=mrgstile
                                                  )
        if len(qs_tile) != 1 :
            print("Can't find tile "+mrgstile)
            exit()
        
        mpolywkt= str(qs_tile[0].geom.ewkt).split(";")
        print(mpolywkt[1])
        
        self.mEODataAccessGateway = EODataAccessGateway(self.user_conf_file_path)
        
        with open(self.providers_conf_file_path, 'r') as stream:
            self.mEODataAccessGateway.update_providers_config(stream)
        
        product_type = 'S1_SAR_GRD'
        
        products, estimated_total_nbr_of_results = self.mEODataAccessGateway.search(
                productType=product_type,
                start=startdate,
                end=enddate,
                geom=mpolywkt[1]
            )
        
        print(
                f"The search has found an estimated number of {estimated_total_nbr_of_results} products matching "
                f"our criteria. It has returned the first {len(products)} ones available."
            )