Skip to content

Commit

Permalink
Fix for rounding negative coordinates.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Apr 13, 2024
1 parent ba7a8ec commit 87f3d4e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/generate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gzip
import json
import math
import os
import re
import shutil
Expand Down Expand Up @@ -461,11 +462,16 @@ def _tile_info(self, lat: float, lon: float) -> tuple[str, str]:
Returns:
tuple[str, str]: Latitude band and tile name.
"""
latitude_band = f"N{int(lat):02d}"
tile_latitude = math.floor(lat)
tile_longitude = math.floor(lon)

latitude_band = f"N{abs(tile_latitude):02d}"
if lon < 0:
tile_name = f"N{int(lat):02d}W{int(abs(lon)):03d}"
tile_name = f"N{abs(tile_latitude):02d}W{abs(abs(tile_longitude)):03d}"
else:
tile_name = f"N{int(lat):02d}E{int(lon):03d}"
tile_name = f"N{abs(tile_latitude):02d}E{abs(tile_longitude):03d}"

self.logger.log(f"Detected tile name: {tile_name} for coordinates: lat {lat}, lon {lon}.")
return latitude_band, tile_name

def _download_tile(self) -> str | None:
Expand Down

0 comments on commit 87f3d4e

Please sign in to comment.