def _filter_overlap(scenes, wkt_geometry, min_overlap=0): """Filter scenes based on the minimum overlap to the area of interest Args: scenes: List of scenes to filter wkt_geometry: Wkt Geometry representation of the area of interest min_overlap: Minimum overlap (0-1) in decimal format between scene geometry and area of interest Returns: Filtered list of scenes """ filtered = [] with wkt2vector(wkt_geometry, srs=4326) as vec1: site_area = vec1.getArea() for scene in scenes: with wkt2vector(scene['footprint'], srs=4326) as vec2: footprint_area = vec2.getArea() with intersect(vec1, vec2) as inter: intersect_area = inter.getArea() overlap = intersect_area / site_area if overlap > min_overlap or ( site_area / footprint_area > 1 and intersect_area / footprint_area > min_overlap): scene['_script_overlap'] = overlap * 100 filtered.append(scene) return filtered
def set_geometries(self, geometries): """Manually set one or more geometries for data search Args: geometries: String or List representation of one or more Wkt Geometries, Geometries have to be in Lat/Lng, EPSG:4326 projection! """ # print('Set geometries:') # print(geometries) if isinstance(geometries, list): self.__geometries = geometries elif isinstance(geometries, str): self.__geometries = [geometries] else: raise Exception( 'geometries parameter needs to be a list or a string') # Test first geometry try: vec = wkt2vector(self.__geometries[0], srs=4326) except RuntimeError as e: raise Exception('The first geometry is not valid! Error: %s' % e) finally: vec = None
def _format_url(self, startindex, wkt_geometry, platform, date_filtering, **keywords): """Format the search URL based on the arguments Args: wkt_geometry: Geometry in Wkt representation platform: Satellite to search in dateFiltering: filter of dates **keywords: Further search parameters from ESA Data Hub Returns: url: String URL to search for this data """ with wkt2vector(wkt_geometry, srs=4326) as vec: bbox = vec.bbox().convert2wkt()[0] query_area = ' AND (footprint:"Intersects(%s)")' % bbox filters = '' for kw in sorted(keywords.keys()): filters += ' AND (%s:%s)' % (kw, keywords[kw]) url = os.path.join( self.__esa_api_url, 'search?format=json&rows=100&start=%s&q=%s%s%s%s' % (startindex, platform, date_filtering, query_area, filters)) return url