[GIS] osmfilter filter for nodes and find the related/nearest street to every node

openstreetmap

I'm successfully managed to filter all nodes of a specific type by using osmfilter:

osmfilter austria.o5m --keep="highway=speed_camera"

Now I have got a lot of nodes like this:

<node id="3906966442" lat="48.2975844" lon="14.2988663" version="1" timestamp="2015-12-23T18:18:11Z" changeset="36131585" uid="180830" user="flaimo">
    <tag k="highway" v="speed_camera"/>
    <tag k="maxspeed" v="50"/>
</node>

And in the end I'm converting it to a CSV using:

osmconvert - --all-to-nodes --csv="@id @lon @lat @timestamp maxspeed"

Which works fine. However in addition to the maxspeed value I'd also be interested in the name of the street where this node is attached too. Since nodes like speed_camera are always attached to a street this should be possible using the Openstreet map dataset.

The only solution I could think of is todo reverse geolocation look up for each node, which however would be very slow. I'd prefer a more performant solution (ideally based on just osmfilter) like keeping all street entries with speed cameras attached in the OSM dataset, but I can't find anyway to do that with osmfilter.

Best Answer

Since nodes like speed_camera are always attached to a street ...

So you mean that a node with tagging for a speed camera is always a child element of a street that it belongs to? Are you sure?

According to the OSM wiki about Relation:enforcement a speed camera can also be next to the belonging street. The connection is done via a so called Relation in the OSM data model.

A complete relation for speed cameras has three elements with according roles: the device, which can be positioned freely, one node with the from-role and anothe with the to-role. These two points have to be child element of the belonging way.

So you should get familiar with the OSM data model about relations, and by finding speed-camera-nodes, you should be able to find the from-and-to nodes, and the parent ay of these two.

Maybe you can use the famous Overpass API or Overpass-turbo where you can create queries for childs and parents of elements and relations.

I recommend to start with a smaller area for testing your own queries, don't search whole Austria for now.

Read all examples and how-tos about overpass-api and -turbo in the OSM wiki ... there are quite good examples.

Related Question