Skip to content

Commit afaa1a5

Browse files
authored
Merge pull request #3 from osm2pgsql-dev/new-polygon-check
Improve the has_area_tags() function in the basic topic
2 parents 0ce9ed7 + c82a8c2 commit afaa1a5

File tree

1 file changed

+106
-31
lines changed

1 file changed

+106
-31
lines changed

themes/basic/init.lua

Lines changed: 106 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,118 @@
66

77
local theme = {}
88

9-
-- Helper function that looks at the tags and decides if this is possibly
10-
-- an area.
9+
local function init_polygon_lookup()
10+
-- Objects with any of the following keys will be treated as polygon
11+
local polygon_keys = {
12+
'abandoned:aeroway',
13+
'abandoned:amenity',
14+
'abandoned:building',
15+
'abandoned:landuse',
16+
'abandoned:power',
17+
'aeroway',
18+
'allotments',
19+
'amenity',
20+
'area:highway',
21+
'building',
22+
'building:part',
23+
'club',
24+
'craft',
25+
'emergency',
26+
'golf',
27+
'harbour',
28+
'healthcare',
29+
'historic',
30+
'landuse',
31+
'leisure',
32+
'man_made',
33+
'military',
34+
'natural',
35+
'office',
36+
'place',
37+
'power',
38+
'public_transport',
39+
'shop',
40+
'tourism',
41+
'water',
42+
'wetland'
43+
}
44+
45+
-- Objects with these key/value combinations will be treated as linestring
46+
local linestring_values = {
47+
aeroway = {'taxiway', 'runway'},
48+
emergency = {'designated', 'destination', 'no', 'official', 'yes'},
49+
golf = {'cartpath', 'hole', 'path'},
50+
historic = {'citywalls'},
51+
leisure = {'track', 'slipway'},
52+
man_made = {'breakwater', 'cutline', 'embankment', 'groyne', 'pipeline'},
53+
natural = {'cliff', 'earth_bank', 'tree_row', 'ridge', 'arete'},
54+
power = {'cable', 'line', 'minor_line'},
55+
tourism = {'yes'}
56+
}
57+
58+
-- Objects with these key/value combinations will be treated as polygon
59+
local polygon_values = {
60+
aerialway = {'station'},
61+
boundary = {'aboriginal_lands', 'national_park', 'protected_area'},
62+
highway = {'services', 'rest_area'},
63+
junction = {'yes'},
64+
railway = {'station'},
65+
waterway = {'dock', 'boatyard', 'fuel', 'riverbank'}
66+
}
67+
68+
local lookup_table = {}
69+
70+
local function init_values(list, set_to)
71+
for key, values in pairs(list) do
72+
for _, value in ipairs(values) do
73+
if lookup_table[key] == nil then
74+
lookup_table[key] = {}
75+
end
76+
lookup_table[key][value] = set_to
77+
end
78+
end
79+
end
80+
81+
init_values(linestring_values, false)
82+
init_values(polygon_values, true)
83+
84+
for _, key in ipairs(polygon_keys) do
85+
if lookup_table[key] == nil then
86+
lookup_table[key] = true
87+
else
88+
lookup_table[key][''] = true
89+
end
90+
end
91+
92+
return lookup_table
93+
end
94+
95+
local is_polygon = init_polygon_lookup()
96+
97+
-- Helper function that looks at the tags and decides if this is an area.
1198
function theme.has_area_tags(tags)
12-
if tags.area == 'yes' then
99+
local area = tags.area
100+
if area == 'yes' then
13101
return true
14102
end
15-
if tags.area == 'no' then
103+
if area == 'no' then
16104
return false
17105
end
18106

19-
return tags.aeroway
20-
or tags.amenity
21-
or tags.building
22-
or tags.harbour
23-
or tags.historic
24-
or tags.landuse
25-
or tags.leisure
26-
or tags.man_made
27-
or tags.military
28-
or tags.natural
29-
or tags.office
30-
or tags.place
31-
or tags.power
32-
or tags.public_transport
33-
or tags.shop
34-
or tags.sport
35-
or tags.tourism
36-
or tags.water
37-
or tags.waterway
38-
or tags.wetland
39-
or tags['abandoned:aeroway']
40-
or tags['abandoned:amenity']
41-
or tags['abandoned:building']
42-
or tags['abandoned:landuse']
43-
or tags['abandoned:power']
44-
or tags['area:highway']
45-
or tags['building:part']
107+
for k, v in pairs(tags) do
108+
local item = is_polygon[k]
109+
if item == true then
110+
return true
111+
end
112+
if item ~= nil then
113+
if item[v] ~= nil then
114+
return item[v]
115+
end
116+
if item[''] ~= nil then
117+
return item[v]
118+
end
119+
end
120+
end
46121
end
47122

48123
return theme

0 commit comments

Comments
 (0)