map now working
This commit is contained in:
@@ -25,6 +25,33 @@ def simplify_track(
|
||||
return [p for (p, _, _), keep in zip(gps_pts, mask) if keep]
|
||||
|
||||
|
||||
def preview_coords(
|
||||
points: list[DataPoint],
|
||||
max_points: int = 20,
|
||||
) -> list[list[float]] | None:
|
||||
"""Return a small list of [lat, lon] pairs for card thumbnail rendering.
|
||||
|
||||
Uses a coarser RDP pass, then subsamples to at most max_points.
|
||||
Returns None if there is no GPS data.
|
||||
"""
|
||||
gps = [(p.lat, p.lon) for p in points if p.lat is not None and p.lon is not None]
|
||||
if len(gps) < 2:
|
||||
return None
|
||||
|
||||
# Coarse RDP (larger epsilon = fewer points)
|
||||
coords = [[lon, lat] for lat, lon in gps]
|
||||
mask = rdp(coords, epsilon=0.001, return_mask=True)
|
||||
reduced = [gps[i] for i, keep in enumerate(mask) if keep]
|
||||
|
||||
# Subsample if still too many
|
||||
if len(reduced) > max_points:
|
||||
step = len(reduced) / max_points
|
||||
reduced = [reduced[int(i * step)] for i in range(max_points)]
|
||||
reduced.append(gps[-1]) # always include the last point
|
||||
|
||||
return [[round(lat, 5), round(lon, 5)] for lat, lon in reduced]
|
||||
|
||||
|
||||
def build_geojson(
|
||||
points: list[DataPoint],
|
||||
activity_id: str,
|
||||
|
||||
Reference in New Issue
Block a user