-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuilding.lua
236 lines (201 loc) · 7.4 KB
/
building.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
require "helpers"
require "style.building_helpers"
local index_spec_file = 'indexes/building.ini'
local indexes_point = get_indexes_from_spec(index_spec_file, 'point')
local indexes_polygon = get_indexes_from_spec(index_spec_file, 'polygon')
local tables = {}
tables.building_point = osm2pgsql.define_table({
name = 'building_point',
schema = schema_name,
ids = { type = 'node', id_column = 'osm_id', create_index = 'unique' },
columns = {
{ column = 'osm_type', type = 'text' , not_null = true},
{ column = 'osm_subtype', type = 'text'},
{ column = 'name', type = 'text' },
{ column = 'levels', type = 'int'},
{ column = 'height', sql_type = 'numeric'},
{ column = 'housenumber', type = 'text'},
{ column = 'street', type = 'text' },
{ column = 'city', type = 'text' },
{ column = 'state', type = 'text'},
{ column = 'postcode', type = 'text'},
{ column = 'address', type = 'text', not_null = true},
{ column = 'wheelchair', type = 'text'},
{ column = 'wheelchair_desc', type = 'text'},
{ column = 'operator', type = 'text'},
{ column = 'geom', type = 'point', projection = srid, not_null = true},
},
indexes = indexes_point
})
tables.building_polygon = osm2pgsql.define_table({
name = 'building_polygon',
schema = schema_name,
ids = { type = 'way', id_column = 'osm_id', create_index = 'unique' },
columns = {
{ column = 'osm_type', type = 'text', not_null = true},
{ column = 'osm_subtype', type = 'text'},
{ column = 'name', type = 'text' },
{ column = 'levels', type = 'int'},
{ column = 'height', sql_type = 'numeric'},
{ column = 'housenumber', type = 'text'},
{ column = 'street', type = 'text' },
{ column = 'city', type = 'text' },
{ column = 'state', type = 'text'},
{ column = 'postcode', type = 'text'},
{ column = 'address', type = 'text', not_null = true},
{ column = 'wheelchair', type = 'text'},
{ column = 'wheelchair_desc', type = 'text'},
{ column = 'operator', type = 'text'},
{ column = 'geom', type = 'multipolygon', projection = srid, not_null = true},
},
indexes = indexes_polygon
})
function building_process_node(object)
local address_only = address_only_building(object.tags)
if not is_first_level_building(object.tags)
and not address_only
then
return
end
local osm_types = get_osm_type_subtype_building(object)
local name = get_name(object.tags)
local housenumber = object.tags['addr:housenumber']
local street = object.tags['addr:street']
local city = object.tags['addr:city']
local state = object.tags['addr:state']
local postcode = object.tags['addr:postcode']
local address = get_address(object.tags)
local wheelchair = object.tags.wheelchair
local wheelchair_desc = get_wheelchair_desc(object.tags)
local levels = object.tags['building:levels']
local height = parse_to_meters(object.tags['height'])
local operator = object.tags.operator
tables.building_point:insert({
osm_type = osm_types.osm_type,
osm_subtype = osm_types.osm_subtype,
name = name,
housenumber = housenumber,
street = street,
city = city,
state = state,
postcode = postcode,
address = address,
wheelchair = wheelchair,
wheelchair_desc = wheelchair_desc,
levels = levels,
height = height,
operator = operator,
geom = object:as_point()
})
end
function building_process_way(object)
local address_only = address_only_building(object.tags)
if not is_first_level_building(object.tags)
and not address_only
then
return
end
if not object.is_closed then
return
end
local osm_types = get_osm_type_subtype_building(object)
local name = get_name(object.tags)
local housenumber = object.tags['addr:housenumber']
local street = object.tags['addr:street']
local city = object.tags['addr:city']
local state = object.tags['addr:state']
local postcode = object.tags['addr:postcode']
local address = get_address(object.tags)
local wheelchair = object.tags.wheelchair
local wheelchair_desc = get_wheelchair_desc(object.tags)
local levels = object.tags['building:levels']
local height = parse_to_meters(object.tags['height'])
local operator = object.tags.operator
tables.building_polygon:insert({
osm_type = osm_types.osm_type,
osm_subtype = osm_types.osm_subtype,
name = name,
housenumber = housenumber,
street = street,
city = city,
state = state,
postcode = postcode,
address = address,
wheelchair = wheelchair,
wheelchair_desc = wheelchair_desc,
levels = levels,
height = height,
operator = operator,
geom = object:as_polygon()
})
end
function building_process_relation(object)
local address_only = address_only_building(object.tags)
if not is_first_level_building(object.tags)
and not address_only
then
return
end
local osm_types = get_osm_type_subtype_building(object)
local name = get_name(object.tags)
local housenumber = object.tags['addr:housenumber']
local street = object.tags['addr:street']
local city = object.tags['addr:city']
local state = object.tags['addr:state']
local postcode = object.tags['addr:postcode']
local address = get_address(object.tags)
local wheelchair = object.tags.wheelchair
local wheelchair_desc = get_wheelchair_desc(object.tags)
local levels = object.tags['building:levels']
local height = parse_to_meters(object.tags['height'])
local operator = object.tags.operator
if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then
tables.building_polygon:insert({
osm_type = osm_types.osm_type,
osm_subtype = osm_types.osm_subtype,
name = name,
housenumber = housenumber,
street = street,
city = city,
state = state,
postcode = postcode,
address = address,
wheelchair = wheelchair,
wheelchair_desc = wheelchair_desc,
levels = levels,
height = height,
operator = operator,
geom = object:as_multipolygon()
})
end
end
if osm2pgsql.process_way == nil then
osm2pgsql.process_way = building_process_way
else
local nested = osm2pgsql.process_way
osm2pgsql.process_way = function(object)
local object_copy = deep_copy(object)
nested(object)
building_process_way(object_copy)
end
end
if osm2pgsql.process_node == nil then
osm2pgsql.process_node = building_process_node
else
local nested = osm2pgsql.process_node
osm2pgsql.process_node = function(object)
local object_copy = deep_copy(object)
nested(object)
building_process_node(object_copy)
end
end
if osm2pgsql.process_relation == nil then
osm2pgsql.process_relation = building_process_relation
else
local nested = osm2pgsql.process_relation
osm2pgsql.process_relation = function(object)
local object_copy = deep_copy(object)
nested(object)
building_process_relation(object_copy)
end
end