Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shortbread: Bring boundaries processing in line with definitions #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 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,21 @@ 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
local disputed = valid_disputed(t)
-- If a relation does not an admin boundary or disputed boundary it has
-- nothing to tell us and we don't need the ways.
if not admin_level and not disputed then
return
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