@@ -33,13 +33,38 @@ local rinfos = {}
3333
3434-- ---------------------------------------------------------------------------
3535
36+ -- Check if this looks like a boundary and return admin_level as number
37+ -- Return nil if this is not a valid boundary.
38+ local function get_admin_level (tags )
39+ local type = tags .type
40+
41+ if type == ' boundary' or type == ' multipolygon' then
42+ local boundary = tags .boundary
43+ if boundary == ' administrative' or boundary == ' disputed' then
44+ return tonumber (tags .admin_level )
45+ end
46+ end
47+ end
48+
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
54+
55+ -- ---------------------------------------------------------------------------
56+
3657themepark :add_proc (' way' , function (object , data )
3758 if osm2pgsql .stage == 1 then
3859 return
3960 end
4061
41- local t = object .tags
4262 local info = rinfos [object .id ]
63+ if not info then
64+ return
65+ end
66+
67+ local t = object .tags
4368 local a = {
4469 admin_level = info .admin_level ,
4570 maritime = (t .maritime and (t .maritime == ' yes' or t .natural == ' coastline' )),
@@ -51,32 +76,28 @@ themepark:add_proc('way', function(object, data)
5176end )
5277
5378themepark :add_proc (' select_relation_members' , function (relation )
54- local t = relation .tags
55- -- Only interested in relations with type=boundary, boundary=administrative
56- if t .type == ' boundary' and t .boundary == ' administrative'
57- and (t .admin_level == ' 2' or t .admin_level == ' 4' ) then
79+ if valid_admin_level (get_admin_level (relation .tags )) then
5880 return { ways = osm2pgsql .way_member_ids (relation ) }
5981 end
6082end )
6183
6284themepark :add_proc (' relation' , function (object , data )
6385 local t = object .tags
64- if t .type ~= ' boundary' then
86+
87+ local admin_level = get_admin_level (t )
88+
89+ if not valid_admin_level (admin_level ) then
6590 return
6691 end
6792
68- if (t .boundary == ' administrative' or t .boundary == ' disputed' )
69- and (t .admin_level == ' 2' or t .admin_level == ' 4' ) then
70- local admin_level = tonumber (t .admin_level )
71- for _ , member in ipairs (object .members ) do
72- if member .type == ' w' then
73- if not rinfos [member .ref ] then
74- rinfos [member .ref ] = { admin_level = admin_level }
75- elseif rinfos [member .ref ].admin_level > admin_level then
76- rinfos [member .ref ].admin_level = admin_level
77- end
78- rinfos [member .ref ].disputed = t .boundary == ' disputed'
93+ for _ , member in ipairs (object .members ) do
94+ if member .type == ' w' then
95+ if not rinfos [member .ref ] then
96+ rinfos [member .ref ] = { admin_level = admin_level }
97+ elseif rinfos [member .ref ].admin_level > admin_level then
98+ rinfos [member .ref ].admin_level = admin_level
7999 end
100+ rinfos [member .ref ].disputed = (t .boundary == ' disputed' )
80101 end
81102 end
82103end )
0 commit comments