diff --git a/scripts/boundary.py b/scripts/boundary.py index 743befe..ce764cd 100644 --- a/scripts/boundary.py +++ b/scripts/boundary.py @@ -28,11 +28,24 @@ def add_dataset(self, filename): overview_level = min(2, num_overviews-1) raw_dataset = None - footprint_options = gdal.FootprintOptions( - ovr=overview_level, dstSRS='EPSG:4326', maxPoints=10000, - callback=gdal.TermProgress_nocb) - dataset = gdal.Open(filename) - footprint = gdal.Footprint("/vsimem/outline.shp", dataset, options=footprint_options) + # Rarely, an image will report having overviews, but gdal.Footprint can't + # find them (likely a gdal bug). If so, retry with no overview. + footprint = None + while True: + try: + footprint_options = gdal.FootprintOptions( + ovr=overview_level, dstSRS='EPSG:4326', maxPoints=10000, + callback=gdal.TermProgress_nocb) + dataset = gdal.Open(filename) + footprint = gdal.Footprint("/vsimem/outline.shp", dataset, options=footprint_options) + break + except RuntimeError as e: + if overview_level is None: + print(f"Failed to read overviews, even though they're present") + raise + print("Couldn't read overviews; using full resolution (slow)") + overview_level = None + if footprint: geometry = footprint.GetLayer(0).GetNextFeature() if geometry: # Tiles can be completely empty diff --git a/scripts/compute_boundary.py b/scripts/compute_boundary.py index 5a35c69..7f9b180 100644 --- a/scripts/compute_boundary.py +++ b/scripts/compute_boundary.py @@ -30,6 +30,8 @@ def main(): help='Input Lidar tiles, or GDAL VRT of tiles') args = parser.parse_args() + gdal.UseExceptions() + # Treat each input as potentially a glob, and then flatten the list input_files = [] for filespec in args.input_files: