+@given("the relations")
+def add_data_to_planet_relations(context):
+ cur = context.db.cursor()
+ for r in context.table:
+ last_node = 0
+ last_way = 0
+ parts = []
+ members = []
+ for m in r['members'].split(','):
+ mid = NominatimID(m)
+ if mid.typ == 'N':
+ parts.insert(last_node, int(mid.oid))
+ members.insert(2 * last_node, mid.cls)
+ members.insert(2 * last_node, 'n' + mid.oid)
+ last_node += 1
+ last_way += 1
+ elif mid.typ == 'W':
+ parts.insert(last_way, int(mid.oid))
+ members.insert(2 * last_way, mid.cls)
+ members.insert(2 * last_way, 'w' + mid.oid)
+ last_way += 1
+ else:
+ parts.append(int(mid.oid))
+ members.extend(('r' + mid.oid, mid.cls))
+
+ tags = []
+ for h in r.headings:
+ if h.startswith("tags+"):
+ tags.extend((h[5:], r[h]))
+
+ cur.execute("""INSERT INTO planet_osm_rels (id, way_off, rel_off, parts, members, tags)
+ VALUES (%s, %s, %s, %s, %s, %s)""",
+ (r['id'], last_node, last_way, parts, members, tags))
+ context.db.commit()
+
+@given("the ways")
+def add_data_to_planet_ways(context):
+ cur = context.db.cursor()
+ for r in context.table:
+ tags = []
+ for h in r.headings:
+ if h.startswith("tags+"):
+ tags.extend((h[5:], r[h]))
+
+ nodes = [ int(x.strip()) for x in r['nodes'].split(',') ]
+
+ cur.execute("INSERT INTO planet_osm_ways (id, nodes, tags) VALUES (%s, %s, %s)",
+ (r['id'], nodes, tags))
+ context.db.commit()