Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few minor tweaks for your tool #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gpx/*.gpx
gpx/**/*.gpx
tiles/
venv/
*.png
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Optimized for cycling activities :bicyclist:

* Minimal Python dependencies (`numpy`+`matplotlib`)
* Fast (parse 3x faster than `gpxpy.parse`)
* Supports non Strava GPX tracks

## Usage

Expand Down Expand Up @@ -52,7 +53,7 @@ command|output
### Requirements

```
python>=3.9
python>=3.8
numpy>=1.20
matplotlib>=3.4
```
Expand Down
20 changes: 16 additions & 4 deletions strava_local_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from argparse import ArgumentParser, Namespace

# globals
from typing import Tuple

HEATMAP_MAX_SIZE = (2160, 3840) # maximum heatmap size in pixel
HEATMAP_MARGIN_SIZE = 32 # margin around heatmap trackpoints in pixel

Expand All @@ -42,7 +44,7 @@
OSM_MAX_TILE_COUNT = 100 # maximum number of tiles to download

# functions
def deg2xy(lat_deg: float, lon_deg: float, zoom: int) -> tuple[float, float]:
def deg2xy(lat_deg: float, lon_deg: float, zoom: int) -> Tuple[float, float]:
"""Returns OSM coordinates (x,y) from (lat,lon) in degree"""

# from https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
Expand All @@ -53,7 +55,7 @@ def deg2xy(lat_deg: float, lon_deg: float, zoom: int) -> tuple[float, float]:

return x, y

def xy2deg(x: float, y: float, zoom: int) -> tuple[float, float]:
def xy2deg(x: float, y: float, zoom: int) -> Tuple[float, float]:
"""Returns (lat, lon) in degree from OSM coordinates (x,y)"""

# from https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
Expand Down Expand Up @@ -107,15 +109,25 @@ def download_tile(tile_url: str, tile_file: str) -> bool:

def main(args: Namespace) -> None:
# read GPX trackpoints
gpx_files = glob.glob('{}/{}'.format(args.dir,
args.filter))
gpx_files = glob.glob('{}/**/{}'.format(args.dir,args.filter), recursive=True)

if not gpx_files:
exit('ERROR no data matching {}/{}'.format(args.dir,
args.filter))

lat_lon_data = []

# converting files
for gpx_file in gpx_files:
print('Converting {}'.format(os.path.basename(gpx_file)))
with open(gpx_file, encoding='utf-8') as file:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding try catch since this is file operation

buffer = file.read()
buffer = buffer.replace("><", ">\n<")
buffer = buffer.replace("\t", "")
with open(gpx_file, "w", encoding='utf-8') as file:
file.write(buffer)

# processing files
for gpx_file in gpx_files:
print('Reading {}'.format(os.path.basename(gpx_file)))

Expand Down