@@ -33,13 +33,38 @@ local rinfos = {}
33
33
34
34
-- ---------------------------------------------------------------------------
35
35
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
+
36
57
themepark :add_proc (' way' , function (object , data )
37
58
if osm2pgsql .stage == 1 then
38
59
return
39
60
end
40
61
41
- local t = object .tags
42
62
local info = rinfos [object .id ]
63
+ if not info then
64
+ return
65
+ end
66
+
67
+ local t = object .tags
43
68
local a = {
44
69
admin_level = info .admin_level ,
45
70
maritime = (t .maritime and (t .maritime == ' yes' or t .natural == ' coastline' )),
@@ -51,32 +76,28 @@ themepark:add_proc('way', function(object, data)
51
76
end )
52
77
53
78
themepark :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
58
80
return { ways = osm2pgsql .way_member_ids (relation ) }
59
81
end
60
82
end )
61
83
62
84
themepark :add_proc (' relation' , function (object , data )
63
85
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
65
90
return
66
91
end
67
92
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
79
99
end
100
+ rinfos [member .ref ].disputed = (t .boundary == ' disputed' )
80
101
end
81
102
end
82
103
end )
0 commit comments