diff --git a/scripts/run_lidar_prominence.py b/scripts/run_lidar_prominence.py index 1643659..f7a0a15 100644 --- a/scripts/run_lidar_prominence.py +++ b/scripts/run_lidar_prominence.py @@ -11,7 +11,6 @@ import argparse import glob -import itertools import math import os import signal @@ -53,11 +52,28 @@ def sign(a): def filename_for_coordinates(x, y): """Return output filename for the given coordinates""" y += TILE_SIZE_DEGREES # Name uses upper left corner - x_int = int(x + epsilon * sign(x)) - y_int = int(y + epsilon * sign(y)) - x_fraction = int(abs(100 * (x - x_int)) + epsilon) % 100 - y_fraction = int(abs(100 * (y - y_int)) + epsilon) % 100 - return f"tile_{y_int:02d}x{y_fraction:02d}_{x_int:03d}x{x_fraction:02d}.flt" + xpart = int(round(x * 100)) + ypart = int(round(y * 100)) + + x_int = int(float(xpart) / 100) + y_int = int(float(ypart) / 100) + x_fraction = abs(xpart) % 100 + y_fraction = abs(ypart) % 100 + + # Handle "-0.1" -> "-00x10" + if xpart < 0: + x_string = f"-{abs(x_int):02d}" + else: + x_string = f"{x_int:03d}" + x_string += f"x{x_fraction:02d}" + + if ypart < 0: + y_string = f"-{abs(y_int):02d}" + else: + y_string = f"{y_int:02d}" + y_string += f"x{y_fraction:02d}" + + return f"tile_{y_string}_{x_string}.flt" def write_multipolygon_to_file(multipolygon, filename): driver = ogr.GetDriverByName("ESRI Shapefile") @@ -244,8 +260,13 @@ def main(): maybe_create_directory(args.tile_dir) # Treat each input as potentially a glob, and then flatten the list - input_files = [ glob.glob(x) for x in args.input_files ] - input_files = list(itertools.chain.from_iterable(input_files)) + input_files = [] + for filespec in args.input_files: + files = glob.glob(filespec) + if len(files) == 0: + print(f"Input filespec {filespec} matched no files; exiting.") + exit(1) + input_files.extend(files) # Build all the VRTs and compute boundary for entire input warped_vrt_filename, bounds = create_vrts(args.tile_dir, input_files,