Phase 2.2: performance optimizations, debug tools, app close fix
This commit is contained in:
@@ -168,6 +168,25 @@ class TerrainService:
|
||||
|
||||
return float(elevation)
|
||||
|
||||
def get_elevation_sync(self, lat: float, lon: float) -> float:
|
||||
"""Sync elevation lookup from memory cache. Returns 0.0 if tile not loaded."""
|
||||
tile_name = self.get_tile_name(lat, lon)
|
||||
tile = self._tile_cache.get(tile_name)
|
||||
if tile is None:
|
||||
return 0.0
|
||||
|
||||
size = tile.shape[0]
|
||||
lat_int = int(lat) if lat >= 0 else int(lat) - 1
|
||||
lon_int = int(lon) if lon >= 0 else int(lon) - 1
|
||||
|
||||
row = int((1 - (lat - lat_int)) * (size - 1))
|
||||
col = int((lon - lon_int) * (size - 1))
|
||||
row = max(0, min(row, size - 1))
|
||||
col = max(0, min(col, size - 1))
|
||||
|
||||
elevation = tile[row, col]
|
||||
return 0.0 if elevation == -32768 else float(elevation)
|
||||
|
||||
async def get_elevation_profile(
|
||||
self,
|
||||
lat1: float, lon1: float,
|
||||
@@ -193,6 +212,30 @@ class TerrainService:
|
||||
|
||||
return profile
|
||||
|
||||
def get_elevation_profile_sync(
|
||||
self,
|
||||
lat1: float, lon1: float,
|
||||
lat2: float, lon2: float,
|
||||
num_points: int = 50
|
||||
) -> List[dict]:
|
||||
"""Sync elevation profile - tiles must be pre-loaded into memory cache."""
|
||||
lats = np.linspace(lat1, lat2, num_points)
|
||||
lons = np.linspace(lon1, lon2, num_points)
|
||||
|
||||
total_distance = self.haversine_distance(lat1, lon1, lat2, lon2)
|
||||
distances = np.linspace(0, total_distance, num_points)
|
||||
|
||||
profile = []
|
||||
for i in range(num_points):
|
||||
profile.append({
|
||||
"lat": float(lats[i]),
|
||||
"lon": float(lons[i]),
|
||||
"elevation": self.get_elevation_sync(float(lats[i]), float(lons[i])),
|
||||
"distance": float(distances[i])
|
||||
})
|
||||
|
||||
return profile
|
||||
|
||||
async def ensure_tiles_for_bbox(
|
||||
self,
|
||||
min_lat: float, min_lon: float,
|
||||
|
||||
Reference in New Issue
Block a user