mocnik-science / osm-python-tools

A library to access OpenStreetMap related services
GNU General Public License v3.0
440 stars 48 forks source link

HTTP error 400: Bad request when using inverted bounding boxes for the overpass API module #64

Closed TheFGFSEagle closed 2 years ago

TheFGFSEagle commented 2 years ago

Hi, I noticed that using the overpass.Overpass.query method, using inverted bounding boxes (i.e. where for bbox=[a, b, c, d] a > c or b > d) I get an HTTP error 400: Bad request. I suggest exchanging the two coordinates when they would produce that error otherwise - do you think that would be possible ? Because else I'd have to do that in the script that uses the OSMPythonTools, and every other user of this module too, which leads to an incredible amount of code duplication. Something like this in the constructor of OSMPythonTools.overpass.overpassQueryBuilder:


if bbox[0] > bbox[2]:
    bbox[0], bbox[2] = bbox[2], bbox[0]
if bbox[1] > bbox[3]:
    bbox[1], bbox[3] = bbox[3], bbox[1]
´´´
mocnik-science commented 2 years ago

Dear @TheFGFSEagle,

Thanks for your request. Changing the code in OSMPythonTools is maybe not a good idea, because if it accepts erroneous cases where a > c or b > d, this means that errors in the arguments are less likely to be detected. I understand well your motivation, but in general this can create issues.

To solve your issues, I rather would propose that you define a function orderArguments that you can use universally like bbox=orderArguments([a, b, c, d]). This would minimize code duplication on your side.

Best, Franz-Benjamin