Skip to content

Commit 771b114

Browse files
authored
Fix lat and lng filenames near 0 for Lidar (#48)
* Fix lat and lng near 0 for Lidar. Incorrect filenames were being generated near the equator and meridian when running in high-resolution (Lidar) mode. * Script update for tile filenames. * Update comment. * Fix roundoff error at 0 coordinate crossing.
1 parent f58bc62 commit 771b114

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

code/flt_loader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ string FltLoader::getFltFilename(double minLat, double minLng, const FileFormat
196196

197197
case FileFormat::Value::CUSTOM: {
198198
int upperLatInt = static_cast<int>(upperLat); // Watch out for "minus 0"
199-
snprintf(buf, sizeof(buf), "tile_%s%02dx%02d_%03dx%02d.flt",
199+
int minLngInt = static_cast<int>(minLng);
200+
snprintf(buf, sizeof(buf), "tile_%s%02dx%02d_%s%03dx%02d.flt",
200201
(upperLatInt >= 0) ? "" : "-",
201202
abs(upperLatInt),
202203
fractionalDegree(upperLat),
203-
static_cast<int>(minLng),
204+
(minLng >= 0) ? "" : "-",
205+
abs(minLngInt),
204206
fractionalDegree(minLng));
205207
break;
206208
}

code/prominence_task.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ string ProminenceTask::getFilenamePrefix() const {
127127

128128
int latHundredths = fractionalDegree(lat);
129129
int lngHundredths = fractionalDegree(lng);
130-
snprintf(filename, sizeof(filename), "prominence-%02dx%02d-%03dx%02d",
131-
static_cast<int>(lat), latHundredths,
132-
static_cast<int>(lng), lngHundredths);
130+
snprintf(filename, sizeof(filename), "prominence-%s%02dx%02d-%s%03dx%02d",
131+
(lat >= 0) ? "" : "-",
132+
static_cast<int>(abs(lat)), latHundredths,
133+
(lng >= 0) ? "" : "-",
134+
static_cast<int>(abs(lng)), lngHundredths);
133135
return mOptions.outputDir + "/" + filename;
134136
}
135137

code/tile_loading_policy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Tile *BasicTileLoadingPolicy::loadInternal(double minLat, double minLng) const {
111111

112112
// If the lat/lng can't be represented exactly in floating point,
113113
// there's sometimes roundoff error when converting to integers for
114-
// tile filenames. Adding a little slop prevents truncation.
114+
// tile filenames. Adding a little slop prevents truncation.
115115
minLat = adjustCoordinate(minLat);
116116
minLng = adjustCoordinate(minLng);
117117

code/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ double adjustCoordinate(double coordinate) {
4848
// A tile is not going to be smaller than 0.1 degrees or so, so this
4949
// amount should be safe.
5050
const double epsilon = 0.001;
51-
return coordinate + ((coordinate >= 0) ? epsilon : -epsilon);
51+
return coordinate + ((coordinate >= -1e-8) ? epsilon : -epsilon);
5252
}
5353

5454
string trim(const string &s) {

scripts/run_prominence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def filename_for_coordinates(x, y, degrees_per_tile):
5555
x_fraction = abs(xpart) % 100
5656
y_fraction = abs(ypart) % 100
5757

58-
# Handle "-0.1" -> "-00x10"
58+
# Handle "-0.1" -> "-000x10"
5959
if xpart < 0:
60-
x_string = f"-{abs(x_int):02d}"
60+
x_string = f"-{abs(x_int):03d}"
6161
else:
6262
x_string = f"{x_int:03d}"
6363
x_string += f"x{x_fraction:02d}"

0 commit comments

Comments
 (0)