drolbr / Overpass-API

A database engine to query the OpenStreetMap data.
http://overpass-api.de
GNU Affero General Public License v3.0
693 stars 90 forks source link

Unify output of objects center #622

Open Mashin6 opened 3 years ago

Mashin6 commented 3 years ago

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>
mmd-osm commented 3 years ago

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.

Mashin6 commented 3 years ago

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>
mmd-osm commented 3 years ago

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.

Mashin6 commented 3 years ago

Ah OK. That makes sense then.

mmd-osm commented 3 years ago

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;
Mashin6 commented 3 years ago

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.

mmd-osm commented 3 years ago

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.

Mashin6 commented 3 years ago

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.

mmd-osm commented 3 years ago

I added some more comments on slack…

drolbr commented 3 years ago

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.