#!/usr/bin/python # Parse an OSM file and add a (if missing) to nodes # which have the specified (e.g. k="amenity"). # The tag_type value (e.g. v="restaurant") is used as the missing name. import sys import xml.etree.ElementTree xml_file = sys.argv[1] tag_type = sys.argv[2] out_file = sys.argv[3] tree = xml.etree.ElementTree.parse(xml_file) for node in tree.getroot().findall(u'node'): tag_k_type = node.find(u"tag[@k='%s']" % (tag_type,)) if tag_k_type != None: # Found node: # # # tag_k_name = node.find(u"tag[@k='name']") if tag_k_name == None: type_value = tag_k_type.get('v') tag = xml.etree.ElementTree.Element('tag', {'k': 'name', 'v': type_value}) node.append(tag) tree.write(out_file, encoding="utf-8", xml_declaration=True)