I filter an osm planet extract using osmfilter. I am only interested in nodes belonging to route=subway relations. After performing this operation, I use osm2psql to load all the data into my postgres db.

The thing is that I don't know to which relation name belongs each node. I mean, I know all nodes belong to route=subway relations, but I don't know the name of the relations.

So, if I have a relation with these tags: route=subway, name='Line 23', I would like that all the nodes belonging to this relation had also the relation tags. For example: name:'5th street station', relation_route=subway, relation_name='Line 23'.

How can I do this?

  • Is this really necessary? What if a node already has a name tag? What if a node belongs to more than one subway relation?
    – scai
    Commented Dec 17, 2014 at 8:35
  • The thing is that I would like to attach to the node all the tags of the relations I'm interested in.
    – Bruno
    Commented Dec 17, 2014 at 15:37

1 Answer 1


I wrote a small nodejs program that performs the task: tags2nodes.

You have to specify the osm input file, the relation you want to filter, the postgres user and db data and the program creates a table to store the ouput nodes with 3 columns: id, tags, and geometry. In the column tags (json stringified by default) you can find, besides the node tags, something like this:

relations : {relationid1:{name:'relation1 name', id:'relation1 id',...}, 
             relationid2:{name:'relation2 name', id:'relation2 id',...}}

Arguments detailed:

 -f      input osm.pbf file
 -u      postgres user
 -p      postgres password
 -h      postgres host
 -d      postgres db name
 -c      osm relation condition json. I.e.: {'route':'subway'}'
 -r      role of members of relation to be filtered. I.e.: stop
 -t      [optional] postgres output table name. Default: tags2nodes
 -j      [optional] output projection. Default: WGS84 (4326)
 --json  [optional] json tags field postgres format. Only valid for Postgres >= 9.3. Default: text
 --jsonb [optional] jsonb tags field postgres format (faster!). Only valid for Postgres >= 9.4. Default: text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.