search.py 965 bytes
#!/usr/bin/env python3
"""
This application enables to perform a spatial query over a collection of image, from the specific ROI (vector or raster)
"""
import argparse
from scenes import load_scenes, Index, raster, vector

# Arguments
parser = argparse.ArgumentParser(description="Search scenes intesecting an ROI",)
parser.add_argument("--pickle_file", help="List of scenes (serialized in pickle format)", required=True)
parser.add_argument("--roi", help="ROI. Can be a vector or a raster", required=True)
params = parser.parse_args()

# Load scenes list
scenes = load_scenes(params.pickle_file)

# spatial index
print("Indexation...")
idx = Index(scenes)

# search
print("Search roi")
bbox_fn = raster.get_bbox_wgs84 if params.roi.lower().endswith(".tif") else vector.get_bbox_wgs84
matches = idx.find(bbox_wgs84=bbox_fn(params.roi))
print(f"{len(matches)} scenes found.")
for i, scene_match in enumerate(matches):
    print(f"Scene #{i}")
    print(scene_match)