Skip to content

Commit

Permalink
Allow --bbox to be a file containing four bounding-box coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 20, 2024
1 parent b6810a9 commit af8616a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,12 @@ dmypy.json
# Pyre type checker
.pyre/

# Strava data
activities.csv
activities/

# Arbitrary extension for bounding box coordinates
*.bbox

# Generated files
*.png
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ Then run from the terminal:
stravavis --help
```

## How to use

If your activity data is in a folder called `activities`, run the following command:

```sh
stravavis activities
```

By default, this will create output images prefixed `strava-`.

If you have an `activities.csv` file:

```sh
stravavis activities --activities_path activities.csv
```

To only map activities contained within a
[bounding box](https://boundingbox.klokantech.com/):

```sh
stravavis activities --bbox 24.782802,59.922486,25.254511,60.29785`
```

Or as a shortcut, save bounding-box coordinates to a file:

```sh
echo 24.782802,59.922486,25.254511,60.29785 > helsinki.bbox
stravavis activities --bbox helsinki.bbox
```

## Examples

### Facets
Expand Down
17 changes: 13 additions & 4 deletions src/stravavis/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,19 @@ def main():
sys.exit(f"No files found matching {args.path}")

if args.bbox:
# Convert comma-separated string into floats
args.lon_min, args.lat_min, args.lon_max, args.lat_max = (
float(x) for x in args.bbox.split(",")
)
try:
bbox_values = args.bbox.split(",")
if len(bbox_values) == 1:
with open(args.bbox) as f:
bbox_values = f.readline().split(",")
args.lon_min, args.lat_min, args.lon_max, args.lat_max = map(
float, bbox_values
)
except ValueError:
sys.exit(
f"Bounding box '{args.bbox}' must be four comma-separated coordinates "
"or a file containing them"
)

if args.activities_path and os.path.isdir(args.activities_path):
args.activities_path = os.path.join(args.activities_path, "activities.csv")
Expand Down

0 comments on commit af8616a

Please sign in to comment.