How do I list all segments for my city?

1,144 views
Skip to first unread message

Joe Murphy

unread,
Jun 25, 2018, 10:28:51 AM6/25/18
to Strava API
Can someone please help me to understand how the to use the bounds param on the /segments/explore endpoint?

I would like to return a list of all segments in my city, but I'm unsure how to define bounds of my city. The doc says:

The latitude and longitude for two points describing a rectangular boundary for the search: [southwest corner latitutde, southwest corner longitude, northeast corner latitude, northeast corner longitude

could someone please help provide an example of how to format this in the call?

Joe Murphy

unread,
Jun 25, 2018, 10:55:44 AM6/25/18
to Strava API

Was able to make some progress but even with a very large bounding box I'm only able to return 10 segments. Any idea how to increase that number or if the results are paginated?  

Joe Murphy

unread,
Jun 25, 2018, 3:28:46 PM6/25/18
to Strava API
NM. It's said it right in the docs, only returns top ten results. 

So it's back to the drawing board. How should I get all segments in a City? Scraping?

Jeffrey Friedl

unread,
Jun 25, 2018, 7:54:53 PM6/25/18
to Joe Murphy, Strava API
> So it's back to the drawing board. How should I get all segments in a City?

Just do a ride that covers every permutation of every combination of streets
in your city, and then fetch the effort list from it. Voila! This will be much
faster than waiting for help from Strava.

Jeffrey

Anthony Christe

unread,
Aug 4, 2018, 6:51:33 PM8/4/18
to Strava API
I'm hoping to try a recursive bounding box approach. I.e., start with a large bounding box, and recursively divide into 4 bounding boxes of equal size. Do this until you hit a base case of your minimum segment length. This approach will still miss segments that don't fall perfectly within one of your bounding boxes. You could run this multiple times, moving the starting bounding box to maybe catch some of those edge cases. I'm hoping to implement this approach this weekend. I'll let you know how it goes.

Joe Murphy

unread,
Sep 15, 2018, 3:26:10 PM9/15/18
to Strava API
How'd that go for you?

Rambo 2000

unread,
Oct 16, 2018, 8:32:21 AM10/16/18
to Strava API
To get nearly all segements you could try the following:
1. Do the recursive bounding box approach to get segments
2. Get each leaderboard from segments you get in step 1
3. Get Koms from each athlete in leaderboard
4. Loop koms and check if bounding box contains kom segment (start or/and end point)

You have to check for duplicates and this can take a while. So Caching could be useful. This approach assume that the riders from the top 10 segments in bounding box also owns koms in your area. This works for me. i found a few "hidden" segments.

Am Samstag, 15. September 2018 21:26:10 UTC+2 schrieb Joe Murphy:
How'd that go for you?

On Saturday, August 4, 2018 at 5:51:33 PM UTC-5, Anthony Christe wrote:
I'm hoping to try a recursive bounding box approach. I.e., start with a large bounding box, and recursively divide into 4 bounding boxes of equal size. Do this until you hit a base case of your minimum segment length. This approach will still miss segments that don't fall perfectly within one of your bounding boxes. You could run this multiple times, moving the starting bounding box to maybe catch some of those edge cases. I'm hoping to implement this approach this weekend. I'll let you know how it goes.

On Monday, June 25, 2018 at 9:28:46 AM UTC-10, Joe Murphy wrote:
NM. It's said it right in the docs, only returns top ten results. 
 segment

Jerry Perullo

unread,
Oct 16, 2018, 10:13:12 PM10/16/18
to Strava API
I did this a while back. Yeah I did recursive squares. A few tips...
First, I set a variable for overlap. Instead of the default 50%, which would create squares with no overlap, I set it around 55% to pick up segments in between squares. So if the edge of my square went from 0-100, one square would have an edge 0-55, another would have 45-100. Get it? I toyed with the variable to find the sweet spot between minimal iterations and not missing segments, and I think the result was around 55%.
Second, I recursed. Each of my 4 overlapping boxes then got broken into 4 overlapping interior boxes and so on. Until...
I stopped when boxes returned less than 10 results.
Third, I did this with a hard coded session key, as I recall, after generating one via oauth. That ran asyncronously on a cron job daily so I could afford if it took an hour.
Strava is now all into only synchronous requests made in the content text of the viewing user, so the whole thing blew up.
So screw it, I scrapped the entire site after 3 or 4 years it was up and running.
Hopefully Strava’s successor is more helpful.
Reply all
Reply to author
Forward
0 new messages