Overpass-API icon indicating copy to clipboard operation
Overpass-API copied to clipboard

Unify output of objects center

Open Mashin6 opened this issue 3 years ago • 10 comments

Currently when trying to retrieve center in xml format the nodes output is different. e.g.

[out:xml];
nwr[natural=water];
out ids center;

returns:

<node id="8042128759" lat="47.0635328" lon="19.4553025"/>
<way id="418578730">
    <center lat="47.5232867" lon="16.2202832"/>
</way>
<relation id="3749159">
    <center lat="49.6789977" lon="18.0248119"/>
</relation>

I think better would be to keep the formatting same across objects so nodes would be reported as

<node id="8042128759">
   <center lat="47.0635328" lon="19.4553025"/>
</node>

Mashin6 avatar May 25 '21 15:05 Mashin6

As you're effectively proposing a breaking change here, I believe this would only be possible by introducing another "out" modifier, which would have to be implemented for every other output format, like json, csv, etc.. That's more code complexity for maybe not an immediately clear benefit.

mmd-osm avatar May 25 '21 15:05 mmd-osm

Fair point, I don't know how many tools depend on this behavior. CSV output behaves correctly as far as I remember (only problem is lack of error messages when query fails).

It is just weird that when I want center, overpass doesn't give me center. e.g. trying simple out center; return lots of "unwanted" information and I though that this was part of a bigger issue.

<way id="51040572">
    <center lat="49.4742319" lon="16.2569839"/>
    <nd ref="650824955"/>
    <nd ref="650824953"/>
    <nd ref="650824949"/>
    <nd ref="650824948"/>
    <nd ref="650824955"/>
    <tag k="dibavod:id" v="415010660015"/>
    <tag k="natural" v="water"/>
    <tag k="source" v="vuv:dibavod:a05"/>
    <tag k="water" v="reservoir"/>
  </way>

Mashin6 avatar May 25 '21 16:05 Mashin6

By the way, this pretty much works as documented here: https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#out

center: This adds only the center of the above mentioned bounding box to ways and relations.

mmd-osm avatar May 26 '21 07:05 mmd-osm

Ah OK. That makes sense then.

Mashin6 avatar May 26 '21 16:05 Mashin6

Found your post on Slack. I'd say you don't really need XML output for your use case anyway. CSV would do fine, processing issues can be recognized using an additional totals row towards the end.

[out:csv(::lat,::lon, ::count; false; " ")][bbox:{{bbox}}];
nwr[building];
out qt center;
out count;

mmd-osm avatar May 27 '21 20:05 mmd-osm

That was actually the original version. The problem was that csv output does not report when something goes wrong with the query and I couldn't distinguished failed requests or no data return.

Mashin6 avatar May 27 '21 23:05 Mashin6

I’m not sure I’m following you. If the query fails b/c of timeout or memory issues, the last control row would always be missing as the query terminated earlier.

mmd-osm avatar May 28 '21 04:05 mmd-osm

Oh you mean the final count. That's an interesting trick I haven't thought of. Thanks! XML output works well now with a bit of crazy parsing grep "lat"| cut -f 2 -d "a" | cut -f 2,4 -d '"' | tr '"' ',' , but switching to csv will save time by downloading only the necessary data.

Mashin6 avatar May 28 '21 04:05 Mashin6

I added some more comments on slack…

mmd-osm avatar May 28 '21 05:05 mmd-osm

Thank you for the input. The more likely way forward is to figure out a way for error messages in the CSV format. Thus I'm marking this one as a wontfix.

drolbr avatar Jun 22 '21 09:06 drolbr