-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoi.lua
365 lines (300 loc) · 10.9 KB
/
poi.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
require "helpers"
local tables = {}
-- Keys to include for further checking. Not all values from each key will be preserved
local poi_first_level_keys = {
'building',
'shop',
'amenity',
'tourism',
'aeroway'
}
local is_first_level_poi = make_check_in_list_func(poi_first_level_keys)
function building_poi(object)
local bldg_name = get_name(object.tags)
if (bldg_name ~= '' or object.tags.operator) then
return true
end
return false
end
local function get_osm_type_subtype(object)
local osm_type_table = {}
if object.tags.shop then
osm_type_table['osm_type'] = 'shop'
osm_type_table['osm_subtype'] = object:grab_tag('shop')
elseif object.tags.amenity then
osm_type_table['osm_type'] = 'amenity'
osm_type_table['osm_subtype'] = object:grab_tag('amenity')
elseif object.tags.building then
osm_type_table['osm_type'] = 'building'
osm_type_table['osm_subtype'] = object:grab_tag('building')
elseif object.tags.tourism then
osm_type_table['osm_type'] = 'tourism'
osm_type_table['osm_subtype'] = object:grab_tag('tourism')
elseif object.tags.aeroway then
osm_type_table['osm_type'] = 'aeroway'
osm_type_table['osm_subtype'] = object:grab_tag('aeroway')
else
-- Cannot be NULL
osm_type_table['osm_type'] = 'Unknown'
osm_type_table['osm_subtype'] = 'Unknown'
end
return osm_type_table
end
tables.poi_point = osm2pgsql.define_table({
name = 'poi_point',
schema = schema_name,
ids = { type = 'node', id_column = 'osm_id' },
columns = {
{ column = 'osm_type', type = 'text', not_null = true },
{ column = 'osm_subtype', type = 'text', not_null = true },
{ column = 'name', type = 'text' },
{ column = 'opening_hours', type = 'text' },
{ column = 'phone', type = 'text' },
{ column = 'email', type = 'text' },
{ column = 'url', type = 'text' },
{ column = 'website', type = 'text' },
{ 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 = 'operator', type = 'text'},
{ column = 'geom', type = 'point' , projection = srid},
}
})
tables.poi_line = osm2pgsql.define_table({
name = 'poi_line',
schema = schema_name,
ids = { type = 'way', id_column = 'osm_id' },
columns = {
{ column = 'osm_type', type = 'text', not_null = true },
{ column = 'osm_subtype', type = 'text', not_null = true },
{ column = 'name', type = 'text' },
{ column = 'opening_hours', type = 'text' },
{ column = 'phone', type = 'text' },
{ column = 'email', type = 'text' },
{ column = 'url', type = 'text' },
{ column = 'website', type = 'text' },
{ 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 = 'operator', type = 'text'},
{ column = 'geom', type = 'linestring' , projection = srid},
}
})
tables.poi_polygon = osm2pgsql.define_table({
name = 'poi_polygon',
schema = schema_name,
ids = { type = 'way', id_column = 'osm_id' },
columns = {
{ column = 'osm_type', type = 'text', not_null = true },
{ column = 'osm_subtype', type = 'text', not_null = true },
{ column = 'name', type = 'text' },
{ column = 'opening_hours', type = 'text' },
{ column = 'phone', type = 'text' },
{ column = 'email', type = 'text' },
{ column = 'url', type = 'text' },
{ column = 'website', type = 'text' },
{ 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 = 'operator', type = 'text'},
{ column = 'member_ids', type = 'jsonb'},
{ column = 'geom', type = 'multipolygon' , projection = srid},
}
})
function poi_process_node(object)
-- Quickly remove any that don't match the 1st level of checks
if not is_first_level_poi(object.tags) then
return
end
if (object.tags.building and not building_poi(object)) then
return
end
local osm_types = get_osm_type_subtype(object)
local name = get_name(object.tags)
local opening_hours = object.tags['opening_hours']
local phone = object.tags['phone']
local email = object.tags['email']
local url = object.tags['url']
local website = object.tags['website']
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 operator = object:grab_tag('operator')
tables.poi_point:add_row({
osm_type = osm_types.osm_type,
osm_subtype = osm_types.osm_subtype,
name = name,
opening_hours = opening_hours,
phone = phone,
email = email,
url = url,
website = website,
housenumber = housenumber,
street = street,
city = city,
state = state,
postcode = postcode,
address = address,
operator = operator,
geom = { create = 'point' }
})
end
function poi_process_way(object)
-- Quickly remove any that don't match the 1st level of checks
if not is_first_level_poi(object.tags) then
return
end
-- Deeper checks for specific osm_type details
if (object.tags.building and not building_poi(object)) then
return
end
-- Gets osm_type and osm_subtype
local osm_types = get_osm_type_subtype(object)
local name = get_name(object.tags)
local opening_hours = object.tags['opening_hours']
local phone = object.tags['phone']
local email = object.tags['email']
local url = object.tags['url']
local website = object.tags['website']
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 operator = object:grab_tag('operator')
if object.is_closed then
tables.poi_polygon:add_row({
osm_type = osm_types.osm_type,
osm_subtype = osm_types.osm_subtype,
name = name,
opening_hours = opening_hours,
phone = phone,
email = email,
url = url,
website = website,
housenumber = housenumber,
street = street,
city = city,
state = state,
postcode = postcode,
address = address,
operator = operator,
geom = { create = 'area' }
})
else
tables.poi_line:add_row({
osm_type = osm_types.osm_type,
osm_subtype = osm_types.osm_subtype,
name = name,
opening_hours = opening_hours,
phone = phone,
email = email,
url = url,
website = website,
housenumber = housenumber,
street = street,
city = city,
state = state,
postcode = postcode,
address = address,
operator = operator,
geom = { create = 'line' }
})
end
end
function poi_process_relation(object)
-- Quickly remove any that don't match the 1st level of checks
if not is_first_level_poi(object.tags) then
return
end
-- Deeper checks for specific osm_type details
if (object.tags.building and not building_poi(object)) then
return
end
-- Gets osm_type and osm_subtype
local osm_types = get_osm_type_subtype(object)
local name = get_name(object.tags)
local opening_hours = object.tags['opening_hours']
local phone = object.tags['phone']
local email = object.tags['email']
local url = object.tags['url']
local website = object.tags['website']
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 operator = object:grab_tag('operator')
local member_ids = osm2pgsql.way_member_ids(object)
if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then
tables.poi_polygon:add_row({
osm_type = osm_types.osm_type,
osm_subtype = osm_types.osm_subtype,
name = name,
opening_hours = opening_hours,
phone = phone,
email = email,
url = url,
website = website,
housenumber = housenumber,
street = street,
city = city,
state = state,
postcode = postcode,
address = address,
operator = operator,
member_ids = member_ids,
geom = { create = 'area' }
})
end
end
if osm2pgsql.process_node == nil then
-- Change function name here
osm2pgsql.process_node = poi_process_node
else
local nested = osm2pgsql.process_node
osm2pgsql.process_node = function(object)
local object_copy = deep_copy(object)
nested(object)
-- Change function name here
poi_process_node(object_copy)
end
end
if osm2pgsql.process_way == nil then
-- Change function name here
osm2pgsql.process_way = poi_process_way
else
local nested = osm2pgsql.process_way
osm2pgsql.process_way = function(object)
local object_copy = deep_copy(object)
nested(object)
-- Change function name here
poi_process_way(object_copy)
end
end
if osm2pgsql.process_relation == nil then
-- Change function name here
osm2pgsql.process_relation = poi_process_relation
else
local nested = osm2pgsql.process_relation
osm2pgsql.process_relation = function(object)
local object_copy = deep_copy(object)
nested(object)
-- Change function name here
poi_process_relation(object_copy)
end
end