Query Overpass API for roads with crossing bridges/railways - openstreetmap

I'm trying to query OpenStreetMaps through the Overpass API.
What I want to query is roads inside a bounding box that has any kind of bridges crossing above, like railway bridges etc.
I found this example, that does just about what I need: http://maxheight.bplaced.net/overpass/map.html
So, the queries I've got look like this:
Railway bridges View in Overpass Turbo
<osm-script output="json" timeout="25">
<!-- Railway bridges -->
<query type="way">
<has-kv k="bridge" regv="^(yes|viaduct)$"/>
<has-kv k="railway" />
<bbox-query {{bbox}}/>
</query>
<!-- Find roads below the above railway bridges -->
<query type="way">
<around radius="0" />
<has-kv k="highway" regv="^((primary|secondary|tertiary|trunk)(_link)?|service|residential|unclassified)$"/>
<has-kv k="maxheight" modv="not" regv="." />
<has-kv k="maxheight:physical" modv="not" regv="." />
<has-kv k="tunnel" modv="not" regv="." />
</query>
<union>
<item />
<recurse type="way-node"/>
</union>
<!-- print results -->
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton" order="quadtile"/>
</osm-script>
Other briges View in Overpass Turbo
<osm-script output="json" timeout="25">
<!-- Bridges -->
<query type="way">
<has-kv k="bridge" regv="^(yes|viaduct)$"/>
<has-kv k="railway" modv="not" regv="." />
<bbox-query {{bbox}}/>
</query>
<!-- Find roads below the above bridges -->
<query type="way">
<around radius="0" />
<has-kv k="highway" regv="^((primary|secondary|tertiary|trunk)(_link)?|service|residential|unclassified)$"/>
<has-kv k="maxheight" modv="not" regv="." />
<has-kv k="maxheight:physical" modv="not" regv="." />
<has-kv k="tunnel" modv="not" regv="." />
</query>
<union>
<item />
<recurse type="way-node"/>
</union>
<!-- print results -->
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton" order="quadtile"/>
</osm-script>
The problem is the second query. It should find bridges crossing a road, and the accompanying road below.
What it does now is return all bridges, except railway bridges - which means it highlights a road with a bike path underneath, a road crossing a lake - which it shouldn't.
I noticed this today, when I drove past a location it highlighted and saw that it was just a bike path under the road.

A few comments regarding the proposed approach above:
Maxheight Map wants to help find streets with missing maximum height information, something which is quite important for truck routing. If I get your use case right, you want to find out about ALL roads where bridges cross. Currently your query would not show any roads, where that maximum height information was already maintained. This is fairly easy to solve if you remove the restriction on both tags "maxheight" and "maxheight:physical" in your query.
As already stated, Maxheight Map merges several layers into one Query. But it would also break a large Boundary Box (bbox) into smaller pieces. The XML query posted above has 4 identical parts inside the UNION operation, which makes things look overly complicated. In fact for the purpose of your use case, you could get away with a much simpler approach (see below).
You don't have to convert your query into XML format. Overpass QL (query language) is perfectly fine for Overpass API and of course Overpass Turbo.
From past experience with Maxheight Map, Overpass API won't give you the solution you're asking for without post-processing the result. If you're familiar with OpenLayers you might want to take a look at the logic I used. Basically you need to find intersections on inner points only, similar to want PostGIS function st_crosses does. Also you would have to take each way's 'layer' information into account as an example.
A very stripped down version (for Overpass Turbo) could look like this. However, you need to make sure that actual highway/bridge types match your requirements, and of course don't forget about post processing your results. Without it your query result will contain quite a number of false positives.
((way({{bbox}})[bridge~"^(yes|viaduct)$"];way(around:0)[highway~"^((primary|secondary|tertiary|trunk)(_link)?|service|residential|unclassified)$"][tunnel!~"."]);>;);out;

The correct query is this. Not only does it get it right in regard to bridges crossing roads, it also combines the two into one query.
I monitored the network on the OSM Truck QA Map, grabbed the POST data of the request to the Overpass API.
I used the Overpass QL converter to turn it into XML.
View query in Overpass Turbo
<osm-script output="json" timeout="20">
<union into="_">
<union into="_">
<union into="_">
<query into="_" type="way">
<bbox-query {{bbox}}/>
<has-kv k="bridge" modv="" regv="^(yes|viaduct)$"/>
<has-kv k="railway" modv="" v=""/>
</query>
<query into="_" type="way">
<around from="_" into="_" lat="" lon="" radius="0"/>
<has-kv k="highway" modv="" regv="^((primary|secondary|tertiary|trunk)(_link)?|service|residential|unclassified)$"/>
<has-kv k="maxheight" modv="not" regv="."/>
<has-kv k="maxheight:physical" modv="not" regv="."/>
<has-kv k="tunnel" modv="not" regv="."/>
</query>
</union>
<recurse from="_" into="_" type="down"/>
</union>
<union into="_">
<union into="_">
<query into="_" type="way">
<bbox-query {{bbox}}/>
<has-kv k="bridge" modv="" regv="^(yes|viaduct)$"/>
<has-kv k="railway" modv="" v=""/>
</query>
<query into="_" type="way">
<around from="_" into="_" lat="" lon="" radius="0"/>
<has-kv k="highway" modv="" regv="^((primary|secondary|tertiary|trunk)(_link)?|service|residential|unclassified)$"/>
<has-kv k="maxheight" modv="not" regv="."/>
<has-kv k="maxheight:physical" modv="not" regv="."/>
<has-kv k="tunnel" modv="not" regv="."/>
</query>
</union>
<recurse from="_" into="_" type="down"/>
</union>
<union into="_">
<union into="_">
<query into="_" type="way">
<bbox-query {{bbox}}/>
<has-kv k="bridge" modv="" regv="^(yes|viaduct)$"/>
<has-kv k="railway" modv="" v=""/>
</query>
<query into="_" type="way">
<around from="_" into="_" lat="" lon="" radius="0"/>
<has-kv k="highway" modv="" regv="^((primary|secondary|tertiary|trunk)(_link)?|service|residential|unclassified)$"/>
<has-kv k="maxheight" modv="not" regv="."/>
<has-kv k="maxheight:physical" modv="not" regv="."/>
<has-kv k="tunnel" modv="not" regv="."/>
</query>
</union>
<recurse from="_" into="_" type="down"/>
</union>
<union into="_">
<union into="_">
<query into="_" type="way">
<bbox-query {{bbox}}/>
<has-kv k="bridge" modv="" regv="^(yes|viaduct)$"/>
<has-kv k="railway" modv="" v=""/>
</query>
<query into="_" type="way">
<around from="_" into="_" lat="" lon="" radius="0"/>
<has-kv k="highway" modv="" regv="^((primary|secondary|tertiary|trunk)(_link)?|service|residential|unclassified)$"/>
<has-kv k="maxheight" modv="not" regv="."/>
<has-kv k="maxheight:physical" modv="not" regv="."/>
<has-kv k="tunnel" modv="not" regv="."/>
</query>
</union>
<recurse from="_" into="_" type="down"/>
</union>
</union>
<print from="_" limit="" mode="body" order="id"/>
</osm-script>

Related

How can I make keys optional in Overpass API queries / osm-scripts?

I found
<osm-script output="json" timeout="25">
<!-- gather results -->
<union>
<!-- query part for: “waterway=*” -->
<query type="way">
<has-kv k="amenity" v="parking"/>
<bbox-query {{bbox}}/>
</query>
</union>
<!-- print results -->
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton" order="quadtile"/>
</osm-script>
to give many parking spots (but not considering streets where you can park at the border - might be a lack of available information).
It does, however, also give private parking spots.
When I add
<has-kv k="access" v="public"/>
it removes the private ones, but also a couple of public ones that seem not to have the attribute. Is there a way to (a) "subtract" elements (e.g. <has-kv k="access" v="private"/>) or (b) make the presence of a key (e.g. access) optional but enforce a value (e.g. public) if it is public?
You can use the negation operator:
<has-kv k="access" modv="not" v="private"/>
Your whole query with the negation from above:
<osm-script output="json" timeout="25">
<!-- gather results -->
<union>
<!-- query part for: “waterway=*” -->
<query type="way">
<has-kv k="amenity" v="parking"/>
<has-kv k="access" modv="not" v="private"/>
<bbox-query {{bbox}}/>
</query>
</union>
<!-- print results -->
<print mode="body"/>
<recurse type="down"/>
<print mode="skeleton" order="quadtile"/>
</osm-script>
Or in more readable OverpassQL:
[timeout:25]
[out:json]
;
(
way
["amenity"="parking"]
["access"!="private"]
{{bbox}};
);
out;
>;
out skel qt;

Overpass API - filter out non-empty tags

Following on from this question, I am trying to query the Overpass API so that it returns all nodes with tags "natural" and "historic" where tag "name" is not emtpy around a set of coordinates with radius 1500m
What I have so far is
<union>
<query type="node">
<around radius="1500" lat="51.1263041473" lon="1.3268128927"/>
<has-kv k="historic"/>
</query>
<query type="node">
<around radius="1500" lat="51.1263041473" lon="1.3268128927"/>
<has-kv k="natural"/>
</query>
</union>
<print/>
This works for both keywords, but doesn't cater for tag "name" not being empty (see: Overpass Turbo)
How can I filter out any node with tag "name" not emtpy?
Hmm, I just found the answer - I didn't know how to put regex into the query. Now I do:
<union>
<query type="node">
<around radius="1500" lat="51.1263041473" lon="1.3268128927"/>
<has-kv k="historic"/>
<has-kv k="name" regv=".+"/>
</query>
<query type="node">
<around radius="1500" lat="51.1263041473" lon="1.3268128927"/>
<has-kv k="natural"/>
<has-kv k="name" regv=".+"/>
</query>

Setting up XMPP Publish-Subscribe nodes: item-forbidden error posting items to the node

I'm trying to set up an XMPP Publish-Subscribe node and to configure it such that when new items are posted to the node, the payload gets automatically delivered to all the subscribers.
For this I am setting the "pubsub#deliver_payloads" configuration option to true, but when posting items to the node, I get an error. Here are the details of what I'm doing:
First I create the node:
<body rid='614709033' xmlns='http://jabber.org/protocol/httpbind' sid='515c16e0'>
<iq to='pubsub.myserver' type='set' xmlns='jabber:client' id='2:sendIQ'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<create node='mynode'/>
</pubsub>
</iq>
</body>
The server replies saying that it's ok:
<body xmlns='http://jabber.org/protocol/httpbind'>
<iq xmlns="jabber:client" type="result" id="2:sendIQ" from="pubsub.myserver" to="user#myserver/515c16e0"/>
</body>
Then I configure the node setting the "pubsub#deliver_payloads" option to "true", in this way:
<body rid='614709036' xmlns='http://jabber.org/protocol/httpbind' sid='515c16e0'>
<iq from='user#myserver' to='pubsub.myserver' type='set' xmlns='jabber:client' id='4:sendIQ'>
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
<configure node='mynode'>
<x xmlns='jabber:x:data' type='submit'>
<field var='pubsub#deliver_payloads'>
<value>true</value>
</field>
</x>
</configure>
</pubsub>
</iq>
</body>
The server replies successfully:
<body xmlns='http://jabber.org/protocol/httpbind'>
<iq xmlns="jabber:client" type="result" id="4:sendIQ" from="pubsub.myserver" to="user#myserver/515c16e0"/>
</body>
But when I try to post some data onto that node, like this:
<body rid='614709038' xmlns='http://jabber.org/protocol/httpbind' sid='515c16e0'>
<iq type='set' to='pubsub.myserver' xmlns='jabber:client' id='5:sendIQ'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<publish node='mynode'>
<item id='test'>
<geoloc xmlns='http://jabber.org/protocol/geoloc' xml:lang='en'>
<lat>0.55</lat>
<lon>1.66</lon>
<timestamp>2014-04-02T15:14:58.783Z</timestamp>
</geoloc>
</item>
</publish>
</pubsub>
</iq>
</body>
The server replies with this error:
<body xmlns='http://jabber.org/protocol/httpbind'>
<iq xmlns="jabber:client" type="error" id="5:sendIQ" from="pubsub.myserver" to="user#myserver/515c16e0">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish node="mynode">
<item id="test">
<geoloc xmlns="http://jabber.org/protocol/geoloc" xml:lang="en">
<lat>0.55</lat>
<lon>1.66</lon>
<timestamp>2014-04-02T15:14:58.783Z</timestamp>
</geoloc>
</item>
</publish>
</pubsub>
<error code="400" type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
<item-forbidden xmlns="http://jabber.org/protocol/pubsub#errors"/>
</error>
</iq>
</body>
I'm using Openfire 3.9.1 as a server, while on the client side I'm using javascript and the Strophe library.
Can anyone explain me why I get this error?
I tried to use different configurations on the node, and when I omit the "pubsub#deliver_payloads" option I get no errors while posting items to the node...
All error conditions are explained in XEP-0060: Publish-Subscribe. You can find the item-forbidden error message at 7.1.3.6 Request Does Not Match Configuration, where it reads:
If the event type is notification + transient and the publisher
provides an item, the service MUST bounce the publication request with
a error and a pubsub-specific error condition of
.
Ok, I see, having only the option "pubsub#deliver_payloads" in the configuration the node is considered a "transient node" (no items allowed).
However, if I change the configuration to make the node "persistent" (i.e. adding the "pubsub#persist_items" and setting it to true), the server should not complain, according to 4.3 Event Types of the XEP-0060, Table 4.
But with this configuration:
<iq from='user#myserver' to='pubsub.myserver' type='set' xmlns='jabber:client' id='5:sendIQ'>
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
<configure node='mynode'>
<x xmlns='jabber:x:data' type='submit'>
<field var='pubsub#persist_items'>
<value>true</value>
</field>
<field var='pubsub#deliver_payloads'>
<value>true</value>
</field>
</x>
</configure>
</pubsub>
</iq>
if I try to post an item to the node I still get the same error:
<iq xmlns="jabber:client" type="error" id="13:sendIQ" from="pubsub.myserver" to="user#myserver/2b35c426">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish node="mynode">
<item id="test">
<geoloc xmlns="http://jabber.org/protocol/geoloc" xml:lang="en">
<lat>0.55</lat>
<lon>1.66</lon>
<timestamp>2014-04-03T08:50:48.682Z</timestamp>
</geoloc>
</item>
</publish>
</pubsub>
<error code="400" type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
<item-forbidden xmlns="http://jabber.org/protocol/pubsub#errors"/>
</error>
</iq>
I solved the problem by simply chenging the value in the configuration from "true" to "1". Actually while reading the XEP-0060 specifications, both "true" - "false" and "1" - "0" values are used in configuration examples. However, in the form that the Openfire server sends me when I ask to configure the node, only "1" - "0" values are used.
With the following configuration all works fine:
<iq from='user#myserver' to='pubsub.myserver' type='set' xmlns='jabber:client' id='5:sendIQ'>
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
<configure node='mynode'>
<x xmlns='jabber:x:data' type='submit'>
<field var='pubsub#persist_items'>
<value>1</value>
</field>
<field var='pubsub#deliver_payloads'>
<value>1</value>
</field>
</x>
</configure>
</pubsub>
</iq>

Is it possible to get all OSM nodes (are not belong to any way) using the Overpass API?

I want to get all OSM nodes (are not belong to any way).
Is it possible?
Understandably, this query get all nodes (includes member of ways)...
<osm-script output="json">
<query type="node">
<bbox-query {{bbox}}/>
</query>
<print/>
</osm-script>
Update 19 Sep 20:20(GMT+9:00)
I tried tyr's query and success!
Actually, this is possible since the latest version of Overpass API:
<osm-script output="json">
<query type="way">
<bbox-query {{bbox}}/>
</query>
<recurse type="way-node" into="waynodes"/>
<query type="node" into="allnodes">
<bbox-query {{bbox}}/>
</query>
<difference>
<item set="allnodes"/>
<item set="waynodes"/>
</difference>
<print/>
</osm-script>
http://overpass-turbo.eu/s/14F
This uses the difference operator to subtract nodes that are member of any ways from all of the nodes.

Unable to publish in pubsub xmpp

i sent the following stanza to ejabbers server after creating a node "test1_node1"
<iq id="publish1" to="pubsub.oomaxmpp.com" type="get" from="admin#oomaxmpp.com/1697575709134613774110793">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish node="test_node1"><item id="qwert12345">
<entry xmlns="http://www.w3.org/2005/Atom">
<title>*publish*</title>
<summary>*1234567890*</summary>
<published>2003-12-13T18:30:02Z</published>
<updated>2003-12-13T18:30:02Z</updated>
</entry>
</item>
</publish>
</pubsub>
</iq>
but i get an error result with following stanza,
<iq id="publish1" xml:lang="en" type="error" to="admin#oomaxmpp.com/1697575709134613774110793" from="pubsub.oomaxmpp.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub"><publish node="test_node1">
<item id="qwert12345"><entry xmlns="http://www.w3.org/2005/Atom">
<title>*publish*</title>
<summary>*1234567890*</summary>
<published>2003-12-13T18:30:02Z</published>
<updated>2003-12-13T18:30:02Z</updated>
</entry>
</item>
</publish>
</pubsub>
<error code="501" type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
i dont understand,if feature was not implemented how nodes were created?
Why cant i publish?