This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
place.lua
69 lines (57 loc) · 1.69 KB
/
place.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--[[
This file is part of ClearTables
@author Paul Norman <penorman@mac.com>
@copyright 2016 Paul Norman, MIT license
]]--
require "common"
local settlements = {
city=true,
town=true,
village=true,
hamlet=true,
isolated_dwelling=true
}
local subregions = {
suburb=true,
neighbourhood=true
}
local other = {
locality=true,
farm=true
}
--- Restrictions population to positive or zero integers
function population (v)
return v and string.find(v, "^%d+$") and tonumber(v) < 2147483647 and tonumber(v) >= 0 and v or nil
end
function accept_place (tags)
-- most tags["place"] will match one of the lookups, so this is quite fast
return (tags["place"] and (settlements[tags["place"]] or subregions[tags["place"]] or other[tags["place"]]))
end
function transform_place (tags)
local cols = {}
if settlements[tags["place"]] then
cols.class = "settlement"
cols.rank = tags["place"]
else
cols.class = subregions[tags["place"]] and "subregion" or tags["place"]
end
cols.name = tags["name"]
cols.names = names(tags)
cols.population = population(tags["population"])
return cols
end
function place_nodes (tags, num_keys)
return generic_node(tags, accept_place, transform_place)
end
function place_ways (tags, num_keys)
return generic_polygon_way(tags, accept_place, transform_place)
end
function place_rels (tags, num_keys)
if (tags["type"] == "multipolygon" and accept_place(tags)) then
return 0, tags
end
return 1, {}
end
function place_rel_members (tags, member_tags, member_roles, membercount)
return generic_multipolygon_members(tags, member_tags, membercount, accept_place, transform_place)
end