Skip to content

Commit deb0eae

Browse files
committed
shortbread: boundaries: Fix disputed boundary processing
Previously a member of multiple relations would take its disputed status from the last relation processed. For example, processing a way that is a member of two relations, with type=boundary boundary=administrative admin_level=2 type=boundary boundary=disputed admin_level=2 would lead to order-dependent results, where disputed only comes from the last relation processed. Another issue was that a relation with type=boundary boundary=disputed and no other tags would not be considered as tonumber(tags.admin_level) is not truth-like. Instead, what is done is to get the disputed status for the relation, and then set it to true for the rinfos in that relation, not setting any existing rinfos to false. They are only set false when creating the entry in rinfos for the first time.
1 parent 4208533 commit deb0eae

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

themes/shortbread_v1/topics/boundaries.lua

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ local function get_admin_level(tags)
4747

4848
if type == 'boundary' or type == 'multipolygon' then
4949
local boundary = tags.boundary
50-
if boundary == 'administrative' and valid_admin_level(tags.admin_level)
51-
or boundary == 'disputed' then
50+
if boundary == 'administrative' and valid_admin_level(tags.admin_level) then
5251
return tonumber(tags.admin_level)
5352
end
5453
end
5554
end
5655

5756

57+
local function valid_disputed(tags)
58+
local type = tags.type
59+
return (type == 'boundary' or type == 'multipolygon') and tags.boundary == 'disputed'
60+
end
61+
5862
-- ---------------------------------------------------------------------------
5963

6064
themepark:add_proc('way', function(object, data)
@@ -68,6 +72,9 @@ themepark:add_proc('way', function(object, data)
6872
end
6973

7074
local t = object.tags
75+
if not info.admin_level then
76+
return
77+
end
7178
local a = {
7279
admin_level = info.admin_level,
7380
maritime = (t.maritime and (t.maritime == 'yes' or t.natural == 'coastline')),
@@ -90,19 +97,21 @@ themepark:add_proc('relation', function(object, data)
9097
local t = object.tags
9198

9299
local admin_level = get_admin_level(t)
93-
94-
if not valid_admin_level(admin_level) then
100+
local disputed = valid_disputed(t)
101+
-- If a relation does not an admin boundary or disputed boundary it has
102+
-- nothing to tell us and we don't need the ways.
103+
if not admin_level and not disputed then
95104
return
96105
end
97106

98107
for _, member in ipairs(object.members) do
99108
if member.type == 'w' then
100109
if not rinfos[member.ref] then
101-
rinfos[member.ref] = { admin_level = admin_level }
110+
rinfos[member.ref] = { admin_level = admin_level, disputed = false }
102111
elseif rinfos[member.ref].admin_level > admin_level then
103112
rinfos[member.ref].admin_level = admin_level
104113
end
105-
rinfos[member.ref].disputed = (t.boundary == 'disputed')
114+
rinfos[member.ref].disputed = disputed or rinfos[member.ref].disputed
106115
end
107116
end
108117
end)

0 commit comments

Comments
 (0)