Skip to content

Commit

Permalink
shortbread: Bring boundaries processing in line with definitions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pnorman committed Feb 19, 2024
1 parent 5ec44a5 commit 624e642
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions themes/shortbread_v1/topics/boundaries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ themepark:add_table{
name = 'boundaries',
ids_type = 'way',
geom = 'linestring',
columns = themepark:columns('core/name', {
{ column = 'admin_level', type = 'int' },
columns = themepark:columns({
{ column = 'admin_level', type = 'int', not_null = true },
{ column = 'maritime', type = 'bool' },
{ column = 'disputed', type = 'bool' },
}),
Expand All @@ -33,23 +33,30 @@ local rinfos = {}

-- ---------------------------------------------------------------------------

-- Check the (string) admin level. Change this depending on which admin
-- levels you want to process. Shortbread only shows 2 and 4.
-- valid values must work with tonumber!
local function valid_admin_level(level)
return level == '2' or level == '4'
end

-- Check if this looks like a boundary and return admin_level as number
-- Return nil if this is not a valid boundary.
-- Return nil if this is not a valid administrative boundary.
local function get_admin_level(tags)
local type = tags.type

if type == 'boundary' or type == 'multipolygon' then
local boundary = tags.boundary
if boundary == 'administrative' or boundary == 'disputed' then
if boundary == 'administrative' and valid_admin_level(tags.admin_level) then
return tonumber(tags.admin_level)
end
end
end

-- Check the (numeric) admin level. Change this depending on which admin
-- levels you want to process. Shortbread only shows 2 and 4.
local function valid_admin_level(level)
return level == 2 or level == 4

local function valid_disputed(tags)
local type = tags.type
return (type == 'boundary' or type == 'multipolygon') and tags.boundary == 'disputed'
end

-- ---------------------------------------------------------------------------
Expand All @@ -65,6 +72,9 @@ themepark:add_proc('way', function(object, data)
end

local t = object.tags
if not info.admin_level then
return
end
local a = {
admin_level = info.admin_level,
maritime = (t.maritime and (t.maritime == 'yes' or t.natural == 'coastline')),
Expand All @@ -76,7 +86,9 @@ themepark:add_proc('way', function(object, data)
end)

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

local admin_level = get_admin_level(t)

if not valid_admin_level(admin_level) then
return
local disputed = valid_disputed(t)
if not admin_level then
print("Not valid admin r"..object.id)
if not disputed then
print("also not disputed")
return
end
end

for _, member in ipairs(object.members) do
if member.type == 'w' then
if not rinfos[member.ref] then
rinfos[member.ref] = { admin_level = admin_level }
rinfos[member.ref] = { admin_level = admin_level, disputed = false }
elseif rinfos[member.ref].admin_level > admin_level then
rinfos[member.ref].admin_level = admin_level
end
rinfos[member.ref].disputed = (t.boundary == 'disputed')
rinfos[member.ref].disputed = disputed or rinfos[member.ref].disputed
end
end
end)
Expand Down

0 comments on commit 624e642

Please sign in to comment.