From 8b963bb3bd4278af3f95e18efab9c52bf7d1b99b Mon Sep 17 00:00:00 2001
From: Remi Cresson <remi.cresson@irstea.fr>
Date: Fri, 1 Apr 2022 20:10:30 +0200
Subject: [PATCH] ADD: use get_bbox_wgs84_from_raster()

---
 test/download_test.py |  2 +-
 test/drs_search.py    | 10 +++-------
 test/drs_stack.py     |  4 +---
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/test/download_test.py b/test/download_test.py
index ab5f9b1..5c84a86 100644
--- a/test/download_test.py
+++ b/test/download_test.py
@@ -13,7 +13,7 @@ parser.add_argument("--day", type=int, default=1)
 params = parser.parse_args()
 
 # Get all scenes in the root_dir
-_, _, bbox = utils.get_epsg_extent_bbox(params.refimage)
+bbox = utils.get_bbox_wgs84_from_raster(params.refimage)
 acq_date = datetime.datetime(year=params.year, month=params.month, day=params.day)
 downloader = TheiaDownloader(config_file=params.theia_cfg)
 downloader.download_closest(bbox_wgs84=bbox, acq_date=acq_date, download_dir=params.download_dir)
diff --git a/test/drs_search.py b/test/drs_search.py
index 94febe5..eb11015 100644
--- a/test/drs_search.py
+++ b/test/drs_search.py
@@ -1,5 +1,4 @@
 import argparse
-import gdal
 from scenes import utils, Index
 
 # Arguments
@@ -17,12 +16,9 @@ idx = Index(scenes)
 
 # search
 print("search roi")
-if params.roi.lower().endswith(".tif"):
-    gdal_ds = gdal.Open(params.roi)
-    bbox = utils.get_bbox_wgs84_from_gdal_ds(gdal_ds=gdal_ds)
-else:
-    bbox = utils.get_bbox_wgs84_from_vector(params.roi)
-matches = idx.find(bbox_wgs84=bbox)
+bbox_fn = utils.get_bbox_wgs84_from_raster if params.roi.lower().endswith(".tif") \
+    else utils.get_bbox_wgs84_from_vector
+matches = idx.find(bbox_wgs84=bbox_fn(params.roi))
 print("{} scenes found.".format(len(matches)))
 #for scene_match in matches:
 #    print(scene_match)
diff --git a/test/drs_stack.py b/test/drs_stack.py
index 7901aa1..7deaaba 100644
--- a/test/drs_stack.py
+++ b/test/drs_stack.py
@@ -1,5 +1,4 @@
 import argparse
-import gdal
 import pyotb
 from scenes import utils, Index
 from scenes.spot import get_spot67_scenes
@@ -20,8 +19,7 @@ idx = Index(scenes)
 
 # search
 print("search roi")
-gdal_ds = gdal.Open(params.roi)
-bbox = utils.get_extent_wgs84(gdal_ds)
+bbox = utils.get_bbox_wgs84_from_raster(params.roi)
 matches = idx.find(bbox_wgs84=bbox)
 print("{} scenes found.".format(len(matches)))
 
-- 
GitLab