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

Allow --bbox to be a file containing four bounding-box coordinates #51

Open
wants to merge 1 commit into
base: main
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
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