Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 0-crossings of coordinates in filenames. #31

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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,
Expand Down