Skip to content

Commit 624e642

Browse files
committed
shortbread: Bring boundaries processing in line with definitions
Shortbread requires ways be part of an administrative boundary, but a boundary=disputed can influence the properties of a way that is also part of boundary=administrative.
1 parent 5ec44a5 commit 624e642

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

themes/shortbread_v1/topics/boundaries.lua

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ themepark:add_table{
1111
name = 'boundaries',
1212
ids_type = 'way',
1313
geom = 'linestring',
14-
columns = themepark:columns('core/name', {
15-
{ column = 'admin_level', type = 'int' },
14+
columns = themepark:columns({
15+
{ column = 'admin_level', type = 'int', not_null = true },
1616
{ column = 'maritime', type = 'bool' },
1717
{ column = 'disputed', type = 'bool' },
1818
}),
@@ -33,23 +33,30 @@ local rinfos = {}
3333

3434
-- ---------------------------------------------------------------------------
3535

36+
-- Check the (string) admin level. Change this depending on which admin
37+
-- levels you want to process. Shortbread only shows 2 and 4.
38+
-- valid values must work with tonumber!
39+
local function valid_admin_level(level)
40+
return level == '2' or level == '4'
41+
end
42+
3643
-- Check if this looks like a boundary and return admin_level as number
37-
-- Return nil if this is not a valid boundary.
44+
-- Return nil if this is not a valid administrative boundary.
3845
local function get_admin_level(tags)
3946
local type = tags.type
4047

4148
if type == 'boundary' or type == 'multipolygon' then
4249
local boundary = tags.boundary
43-
if boundary == 'administrative' or boundary == 'disputed' then
50+
if boundary == 'administrative' and valid_admin_level(tags.admin_level) then
4451
return tonumber(tags.admin_level)
4552
end
4653
end
4754
end
4855

49-
-- Check the (numeric) admin level. Change this depending on which admin
50-
-- levels you want to process. Shortbread only shows 2 and 4.
51-
local function valid_admin_level(level)
52-
return level == 2 or level == 4
56+
57+
local function valid_disputed(tags)
58+
local type = tags.type
59+
return (type == 'boundary' or type == 'multipolygon') and tags.boundary == 'disputed'
5360
end
5461

5562
-- ---------------------------------------------------------------------------
@@ -65,6 +72,9 @@ themepark:add_proc('way', function(object, data)
6572
end
6673

6774
local t = object.tags
75+
if not info.admin_level then
76+
return
77+
end
6878
local a = {
6979
admin_level = info.admin_level,
7080
maritime = (t.maritime and (t.maritime == 'yes' or t.natural == 'coastline')),
@@ -76,7 +86,9 @@ themepark:add_proc('way', function(object, data)
7686
end)
7787

7888
themepark:add_proc('select_relation_members', function(relation)
79-
if valid_admin_level(get_admin_level(relation.tags)) then
89+
-- It isn't necessary to process boundary=disputed relations separately because
90+
-- if they have an admin_level from another relation they will get added anyways.
91+
if valid_admin_level(relation.tags.admin_level) then
8092
return { ways = osm2pgsql.way_member_ids(relation) }
8193
end
8294
end)
@@ -85,19 +97,23 @@ themepark:add_proc('relation', function(object, data)
8597
local t = object.tags
8698

8799
local admin_level = get_admin_level(t)
88-
89-
if not valid_admin_level(admin_level) then
90-
return
100+
local disputed = valid_disputed(t)
101+
if not admin_level then
102+
print("Not valid admin r"..object.id)
103+
if not disputed then
104+
print("also not disputed")
105+
return
106+
end
91107
end
92108

93109
for _, member in ipairs(object.members) do
94110
if member.type == 'w' then
95111
if not rinfos[member.ref] then
96-
rinfos[member.ref] = { admin_level = admin_level }
112+
rinfos[member.ref] = { admin_level = admin_level, disputed = false }
97113
elseif rinfos[member.ref].admin_level > admin_level then
98114
rinfos[member.ref].admin_level = admin_level
99115
end
100-
rinfos[member.ref].disputed = (t.boundary == 'disputed')
116+
rinfos[member.ref].disputed = disputed or rinfos[member.ref].disputed
101117
end
102118
end
103119
end)

0 commit comments

Comments
 (0)