Skip to content

Commit

Permalink
Handle 0-crossings of coordinates in filenames. (#31)
Browse files Browse the repository at this point in the history
* Handle crossing 0 in coordinates in filenames.

* Fail if any input filespec matches no files.
  • Loading branch information
akirmse authored Apr 2, 2024
1 parent 71ac84d commit 2797962
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions scripts/run_lidar_prominence.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import argparse
import glob
import itertools
import math
import os
import signal
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -249,8 +265,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,
Expand Down

0 comments on commit 2797962

Please sign in to comment.