|
| 1 | + |
| 2 | +local tables = {} |
| 3 | + |
| 4 | +tables.highways = osm2pgsql.define_table{ |
| 5 | + name = 'osm2pgsql_test_highways', |
| 6 | + ids = { type = 'way', id_column = 'way_id' }, |
| 7 | + columns = { |
| 8 | + { column = 'tags', type = 'hstore' }, |
| 9 | + { column = 'refs', type = 'text' }, |
| 10 | + { column = 'geom', type = 'linestring' }, |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +tables.routes = osm2pgsql.define_table{ |
| 15 | + name = 'osm2pgsql_test_routes', |
| 16 | + ids = { type = 'relation', id_column = 'rel_id' }, |
| 17 | + columns = { |
| 18 | + { column = 'tags', type = 'hstore' }, |
| 19 | + { column = 'members', type = 'text' }, |
| 20 | + { column = 'geom', type = 'multilinestring' }, |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +local w2r = {} |
| 25 | + |
| 26 | +function osm2pgsql.process_way(object) |
| 27 | + if osm2pgsql.stage == 1 then |
| 28 | + return |
| 29 | + end |
| 30 | + |
| 31 | + local row = { |
| 32 | + tags = object.tags, |
| 33 | + geom = { create = 'line' } |
| 34 | + } |
| 35 | + |
| 36 | + local d = w2r[object.id] |
| 37 | + if d then |
| 38 | + local refs = {} |
| 39 | + for rel_id, rel_ref in pairs(d) do |
| 40 | + refs[#refs + 1] = rel_ref |
| 41 | + end |
| 42 | + table.sort(refs) |
| 43 | + |
| 44 | + row.refs = table.concat(refs, ',') |
| 45 | + end |
| 46 | + |
| 47 | + tables.highways:add_row(row) |
| 48 | +end |
| 49 | + |
| 50 | +function osm2pgsql.select_relation_members(relation) |
| 51 | + if relation.tags.type == 'route' then |
| 52 | + return { ways = osm2pgsql.way_member_ids(relation) } |
| 53 | + end |
| 54 | +end |
| 55 | + |
| 56 | +function osm2pgsql.process_relation(object) |
| 57 | + if object.tags.type ~= 'route' then |
| 58 | + return |
| 59 | + end |
| 60 | + |
| 61 | + local mlist = {} |
| 62 | + for _, member in ipairs(object.members) do |
| 63 | + if member.type == 'w' then |
| 64 | + if not w2r[member.ref] then |
| 65 | + w2r[member.ref] = {} |
| 66 | + end |
| 67 | + w2r[member.ref][object.id] = object.tags.ref |
| 68 | + mlist[#mlist + 1] = member.ref |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + tables.routes:add_row({ |
| 73 | + tags = object.tags, |
| 74 | + members = table.concat(mlist, ','), |
| 75 | + geom = { create = 'line' } |
| 76 | + }) |
| 77 | +end |
| 78 | + |
0 commit comments