Skip to content

Commit 4208533

Browse files
committed
shortbread: boundaries: Require admin_level to be one of the valid values
Shortbread says 2 and 4 are the valid values of admin_level, so this doesn't look at a relation that is only tagged with type=boundary boundary=administrative and has no admin_level tagging. This doesn't strictly comply with shortbread because a member of a admin_level 3 and admin_level 4 relation should get admin_level set to 3 but I don't believe that's the intent of the spec.
1 parent 5ec44a5 commit 4208533

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

themes/shortbread_v1/topics/boundaries.lua

Lines changed: 15 additions & 10 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,24 +33,27 @@ 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)
51+
or boundary == 'disputed' then
4452
return tonumber(tags.admin_level)
4553
end
4654
end
4755
end
4856

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
53-
end
5457

5558
-- ---------------------------------------------------------------------------
5659

@@ -76,7 +79,9 @@ themepark:add_proc('way', function(object, data)
7679
end)
7780

7881
themepark:add_proc('select_relation_members', function(relation)
79-
if valid_admin_level(get_admin_level(relation.tags)) then
82+
-- It isn't necessary to process boundary=disputed relations separately because
83+
-- if they have an admin_level from another relation they will get added anyways.
84+
if valid_admin_level(relation.tags.admin_level) then
8085
return { ways = osm2pgsql.way_member_ids(relation) }
8186
end
8287
end)

0 commit comments

Comments
 (0)