Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
__pycache__
.claude
20 changes: 10 additions & 10 deletions code/prominence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,16 @@ int main(int argc, char **argv) {
auto threadPool = std::make_unique<ThreadPool>(numThreads);
int num_tiles_processed = 0;
vector<std::future<bool>> results;
// Use double precision to avoid accumulating floating-point error during loop
double lat = bounds[0];
while (lat < bounds[1]) {
// Latitude range is half-open [bounds[0], bounds[1]); longitude range is
// closed [bounds[2], bounds[3]] and traversed east-to-west.
int numLatTiles = static_cast<int>(std::round((bounds[1] - bounds[0]) / degreesAcross));
int numLngTiles = static_cast<int>(std::round((bounds[3] - bounds[2]) / degreesAcross));
for (int latIndex = 0; latIndex < numLatTiles; ++latIndex) {
double lat = bounds[0] + latIndex * degreesAcross;
// Go east-to-west to take advantage of some tile caching, since we need pixels
// from our eastern neighbor.
double lng = bounds[3];
while (lng >= bounds[2]) {
for (int lngIndex = 0; lngIndex <= numLngTiles; ++lngIndex) {
double lng = bounds[3] - lngIndex * degreesAcross;
// Allow specifying longitude ranges that span the antimeridian (lng > 180)
auto wrappedLng = lng;
if (!fileFormat->isUtm() && wrappedLng >= 180) {
Expand All @@ -229,8 +232,8 @@ int main(int argc, char **argv) {
fileFormat->coordinateSystemForOrigin(lat, wrappedLng, utmZone));

// Skip tiles that don't intersect filtering polygon
if (!filter.intersects(lat, lat + fileFormat->degreesAcross(),
lng, lng + fileFormat->degreesAcross())) {
if (!filter.intersects(lat, lat + degreesAcross,
lng, lng + degreesAcross)) {
VLOG(3) << "Skipping tile that doesn't intersect polygon " << lat << " " << lng;
} else {
// Actually calculate prominence
Expand All @@ -239,10 +242,7 @@ int main(int argc, char **argv) {
return task->run(lat, wrappedLng, *coordinateSystem);
}));
}

lng -= fileFormat->degreesAcross();
}
lat += fileFormat->degreesAcross();
}

for (auto && result : results) {
Expand Down
8 changes: 7 additions & 1 deletion scripts/run_prominence.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ def get_extent_transformed(src_ds, target_srs_name):
transform = osr.CoordinateTransformation(src_srs, target_srs)
projected = [transform.TransformPoint(x, y)[:2] for x, y in corners]

xs = [(x + 180) % 360 - 180 for x, _ in projected] # Deal with antimeridian
raw_xs = [x for x, _ in projected]
ys = [y for _, y in projected]
# A dataset covering the whole globe in longitude (e.g. -180..180) would have
# its right edge wrapped onto its left edge by the antimeridian normalization
# below, collapsing the extent to zero width. Handle it explicitly.
if max(raw_xs) - min(raw_xs) >= 360 - 1e-6:
return -180, min(ys), 180, max(ys)
xs = [(x + 180) % 360 - 180 for x in raw_xs] # Deal with antimeridian
return min(xs), min(ys), max(xs), max(ys)

def create_vrts(tile_dir, input_files, skip_boundary, tile_srs, threads):
Expand Down
Loading