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

lat() and lon() fail for points outside of a convert statement #737

Open
ryanfae opened this issue Aug 17, 2024 · 6 comments
Open

lat() and lon() fail for points outside of a convert statement #737

ryanfae opened this issue Aug 17, 2024 · 6 comments

Comments

@ryanfae
Copy link

ryanfae commented Aug 17, 2024

makeing a point (with pt(eval, eval)) creates a geometry with a coordinate pair inside of it. For convert statements, lat() and lon() obtains the latitude and longitude from that coordinate pair, like so: https://overpass-turbo.eu/s/1PTS

But for non-convert statements attempting to use lat() and lon() directly, like next to an around clause, it fails and instead returns (0, 0): https://overpass-turbo.eu/s/1PTU

The expected behavior is to return 40 (or a float variant) from lat() and -80 (or a float variant) from lon(), and for nwr(around:20, lat(), lon()); to find nodes, ways, and relations within 20 meters of (40, -80).

@mmd-osm
Copy link
Contributor

mmd-osm commented Aug 18, 2024

The reason why this doesn't work is that around expects actual lat / lon values, rather than an "evaluator". Both lat() and lon() are examples of an evaluator. You can only use them in statements that explicitly support them, like the first example you've mentioned (pt(eval, eval)). Please refer to the documentation for further details.

@ryanfae
Copy link
Author

ryanfae commented Aug 18, 2024

Ah, I see.

May I ask why that's a restriction? That seems to stop any conversions between nodes and pts (and thus ways and lstrs, and relations and polys), unless I'm missing something in the docs, which could be useful in cases of drawing linestrings and polygons based on existing OSM data.

It also prevents one potential use of Overpass for geolocation of images, which is what I use it for outside of mapping. The inability to reference pts outside of a geometric context, like with around, means that additional coordinate data obtained from other sources cannot be used in supplement to the existing OSM data Overpass provides an interface for. I can provide a full example if this explanation doesn't make sense.

@mmd-osm
Copy link
Contributor

mmd-osm commented Aug 19, 2024

Well, since you're anyway working with external data, you could easily rewrite your example as nwr(around:20, 40, -80);out geom;. There's really no need to use pt here.

@ryanfae
Copy link
Author

ryanfae commented Aug 19, 2024

That's true, but it gets really painful to work with past a point.

Let's say I wanted highways within 20 meters of a list of hundreds of coordinates—(40, -80), (50, -100), and so on. I'd need to write nwr["highway"](around:20, 40, -80);, then nwr["highway"](around:20, 50, -100);, and then again for every pair in the list. This is doable (with a few key combinations) in any modern text editor, but then if I need to change that query at all, I need to change it in every line, a task that involves cutting the text out of something like Overpass Turbo, doing some find-and-replace query, re-copying and re-pasting it, and tabbing it back in for style. It becomes really annoying when done frequently.

Being able to 'store' those values, as the ability to reference between pts in around statements would allow, makes this much easier: Just throw the pts in a set and foreach over them. The repeated text is minimal (5-6 characters), and the main query only has to be typed once for easy reading.

@mmd-osm
Copy link
Contributor

mmd-osm commented Aug 19, 2024

Well, around also supports a lists of lat/lons, for a use case that sounds like you want to download objects along some virtual way. See https://www.openstreetmap.org/user/mmd/diary/42055 for a few examples. In general, I'd recommend to generate queries using code (like Python, Javascript or whatever works for you). Copy and pasting in overpass turbo will probably be a huge time sink. Better directly talk to Overpass API from your code.

@ryanfae
Copy link
Author

ryanfae commented Aug 19, 2024

Oh, that's amazing! Both of those solutions are useful to me and remedy the latter issue. Thank you!

(For what it's worth, I still think that node to pt conversion (and everything it implies) would be useful if it's easy to implement, but it's not something I personally use.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants