-
Notifications
You must be signed in to change notification settings - Fork 826
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
Picking the first polygon/multipolygon found in graph_from_place() #320
Comments
This is an interesting idea. I'm a bit apprehensive about it because automating the (multi)polygon search can open up the user to all kinds of unexpected behavior when they get a county or metro or even downtown definition of what they were expecting to be a municipality (as can happen in some places). The value of making |
Got it, so in you actually want people to look up the results and figure out which one they need before calling When I first posted it it seemed like a convenience feature but its potential issues are not worth it I guess. Feel free to close the request! |
Thank you for redirecting me here, @gboeing! Additionally, maybe one could add a magic "auto" or -1 value for which_result that actually does the auto-selection when specified. That would allow the user fine grained control without hiding complexity. I'd also offer to implement, but get in line behind @Jukurrpa ;) |
Thanks @kenomaerz
If this feature gets implemented, I think this would be the right way to do it. What I might recommend though, would be to leave the current default argument The other thing that I mentioned in an earlier comment is that we'd want to propagate this functionality consistently through to all the other functions that use polygons to query overpass. Off the top of my head, this would include at a minimum the I'm going to reopen this issue because I think I'm open to this implementation if you'd like to take a crack at it.
Note that OSMnx does currently log a warning if the geometry is not a (multi)polygon. This warning does not explicitly point the user to the |
That all sounds reasonable to me, I'll take a stab at it. I cannot promise any timelines right now, but let you know once I have some progress. I do not yet have an overview over the other functions that need a similar treatment - I'll look at the modules you named, but the solution will probably require some review in regards to what else needs attention. |
I have taken a pass at this today in PR #536. @Jukurrpa @kenomaerz if you'd both be so kind as to review and test that PR to see if it works as expected with a variety of queries, I'd be grateful. |
Problem description (what did you do, what did you expect to happen, and what actually happened)
I have a script that uses osmnx's
graph_from_place()
to fetch and manipulate OSM data within the boundaries of cities. The script can potentially be run on virtually any city.I've encountered issues for some cities where their administrative boundaries weren't the first result given by OSM's nominatim API, such as Toronto, Canada where the first result is the city's POI, causing the method to throw a
ValueError
as it's a point. Because I can't know this in advance, I need to have a loop that callsgraph_from_place()
withwhich_result=1
, then 2, etc. until the boundaries are found. This works but is not super intuitive.I was wondering if a new parameter could be added to tell
graph_from_place()
to use the first (multi)polygon it finds, with a maximum number of results to check.As an example,
osmnx.graph_from_place('Toronto, Canada', find_within_results=5)
would get the five first results from OSM and use the first one that's a (multi)polygon. Actual name of the parameter to be defined of course :) This new parameter andwhich_result
would be mutually exclusive. From reading the code it would mainly imply changinggdf_from_place()
to accept this new parameter as well and use it as a limit forosm_polygon_download()
and loop through the results.If that sounds reasonable I'd be interested in implementing it.
The text was updated successfully, but these errors were encountered: