Skip to content

Commit

Permalink
Work around potential GDAL bug reading overviews.
Browse files Browse the repository at this point in the history
  • Loading branch information
akirmse committed Jun 26, 2024
1 parent a7ea61e commit 81214c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 18 additions & 5 deletions scripts/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/compute_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 81214c3

Please sign in to comment.