|
| 1 | +-- This is an example Lua transform for a multi style |
| 2 | +-- It is not intended for use directly with --tag-transform-script but |
| 3 | +-- for use from multi.style.json |
| 4 | +-- |
| 5 | +-- See docs/lua.md and docs/multi.md |
| 6 | + |
| 7 | +-- A function to determine if the tags make the object "interesting" to the buildings table |
| 8 | +function building_interesting (keyvals) |
| 9 | + return keyvals["building"] and keyvals["building"] ~= "no" |
| 10 | +end |
| 11 | + |
| 12 | +function building_ways (keyvals, num_keys) |
| 13 | + return generic_ways(building_interesting, keyvals) |
| 14 | +end |
| 15 | + |
| 16 | +function building_rels (keyvals, num_keys) |
| 17 | + return generic_rels(building_interesting, keyvals) |
| 18 | +end |
| 19 | + |
| 20 | +function builing_rel_members (keyvals, keyvaluemembers, roles, membercount) |
| 21 | + return generic_rel_members(building_interesting, keyvals, keyvaluemembers, roles, membercount) |
| 22 | +end |
| 23 | + |
| 24 | +function bus_nodes_proc (keyvals, num_tags) |
| 25 | + if keyvals["highway"] == "bus_stop" then |
| 26 | + tags = keyvals |
| 27 | + -- Turns values into true unless they're no, leaving empty tags as null. |
| 28 | + -- This lets these columns be boolean, vastly simplifying stylesheet |
| 29 | + -- logic |
| 30 | + if tags["shelter"] then |
| 31 | + -- Checks if the value is no or false, then returns a string that can be turned into a boolean |
| 32 | + tags["shelter"] = ((tags["shelter"] ~= "no" and tags["shelter"] ~= "false") and "true" or "false") |
| 33 | + end |
| 34 | + if tags["bench"] then |
| 35 | + tags["bench"] = ((tags["bench"] ~= "no" and tags["bench"] ~= "false") and "true" or "false") |
| 36 | + end |
| 37 | + if tags["wheelchair"] then |
| 38 | + tags["wheelchair"] = ((tags["wheelchair"] ~= "no" and tags["wheelchair"] ~= "false") and "true" or "false") |
| 39 | + end |
| 40 | + return 0, tags |
| 41 | + else |
| 42 | + return 1, {} |
| 43 | + end |
| 44 | +end |
| 45 | + |
| 46 | +-- This function gets rid of something we don't care about |
| 47 | +function drop_all (...) |
| 48 | + return 1, {} |
| 49 | +end |
| 50 | + |
| 51 | +-- A generic way to process ways, given a function which determines if tags are interesting |
| 52 | +function generic_ways (f, kv) |
| 53 | + if f(kv) then |
| 54 | + tags = kv |
| 55 | + return 0, tags, 1, 0 |
| 56 | + else |
| 57 | + return 1, {}, 0, 0 |
| 58 | + end |
| 59 | +end |
| 60 | + |
| 61 | +-- A generic way to process relations, given a function which determines if tags are interesting |
| 62 | +function generic_rels (f, kv) |
| 63 | + if kv["type"] == "multipolygon" and f(kv) then |
| 64 | + tags = kv |
| 65 | + return 0, tags |
| 66 | + else |
| 67 | + return 1, {} |
| 68 | + end |
| 69 | +end |
| 70 | + |
| 71 | +-- Basically taken from style.lua |
| 72 | +function generic_rel_members (f, keyvals, keyvaluemembers, roles, membercount) |
| 73 | + filter = 0 |
| 74 | + boundary = 0 |
| 75 | + polygon = 0 |
| 76 | + roads = 0 |
| 77 | + |
| 78 | + --mark each way of the relation to tell the caller if its going |
| 79 | + --to be used in the relation or by itself as its own standalone way |
| 80 | + --we start by assuming each way will not be used as part of the relation |
| 81 | + membersuperseeded = {} |
| 82 | + for i = 1, membercount do |
| 83 | + membersuperseeded[i] = 0 |
| 84 | + end |
| 85 | + |
| 86 | + --remember the type on the relation and erase it from the tags |
| 87 | + type = keyvals["type"] |
| 88 | + keyvals["type"] = nil |
| 89 | + |
| 90 | + if (type == "multipolygon") and keyvals["boundary"] == nil then |
| 91 | + --check if this relation has tags we care about |
| 92 | + polygon = 1 |
| 93 | + filter = f(keyvals) |
| 94 | + |
| 95 | + --if the relation didn't have the tags we need go grab the tags from |
| 96 | + --any members that are marked as outers of the multipolygon |
| 97 | + if (filter == 1) then |
| 98 | + for i = 1,membercount do |
| 99 | + if (roles[i] == "outer") then |
| 100 | + for j,k in ipairs(tags) do |
| 101 | + v = keyvaluemembers[i][k] |
| 102 | + if v then |
| 103 | + keyvals[k] = v |
| 104 | + filter = 0 |
| 105 | + end |
| 106 | + end |
| 107 | + end |
| 108 | + end |
| 109 | + end |
| 110 | + if filter == 1 then |
| 111 | + return filter, keyvals, membersuperseeded, boundary, polygon, roads |
| 112 | + end |
| 113 | + |
| 114 | + --for each tag of each member if the relation have the tag or has a non matching value for it |
| 115 | + --then we say the member will not be used in the relation and is there for not superseeded |
| 116 | + --ie it is kept as a standalone way |
| 117 | + for i = 1,membercount do |
| 118 | + superseeded = 1 |
| 119 | + for k,v in pairs(keyvaluemembers[i]) do |
| 120 | + if ((keyvals[k] == nil) or (keyvals[k] ~= v)) then |
| 121 | + superseeded = 0; |
| 122 | + break |
| 123 | + end |
| 124 | + end |
| 125 | + membersuperseeded[i] = superseeded |
| 126 | + end |
| 127 | + end |
| 128 | + |
| 129 | + return filter, keyvals, membersuperseeded, boundary, polygon, roads |
| 130 | +end |
0 commit comments