Skip to content

Commit 5d7dcc3

Browse files
committed
Add support for callbacks that are new in osm2pgsql 2.0
* after_nodes/ways/relations * process_untagged_node/way/relation
1 parent 7efc00d commit 5d7dcc3

File tree

2 files changed

+53
-31
lines changed

2 files changed

+53
-31
lines changed

.luacheckrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,30 @@ stds.osm2pgsql = {
1818
process_relation = {
1919
read_only = false
2020
},
21+
process_untagged_node = {
22+
read_only = false
23+
},
24+
process_untagged_way = {
25+
read_only = false
26+
},
27+
process_untagged_relation = {
28+
read_only = false
29+
},
2130
select_relation_members = {
2231
read_only = false
2332
},
2433
process_gen = {
2534
read_only = false
2635
},
36+
after_nodes = {
37+
read_only = false
38+
},
39+
after_ways = {
40+
read_only = false
41+
},
42+
after_relations = {
43+
read_only = false
44+
},
2745
},
2846
other_fields = true,
2947
}

lua/themepark.lua

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ local themepark = {
5757
node = {},
5858
way = {},
5959
relation = {},
60+
untagged_node = {},
61+
untagged_way = {},
62+
untagged_relation = {},
6063
area = {},
6164
select_relation_members = {},
65+
after_nodes = {},
66+
after_ways = {},
67+
after_relations = {},
6268
gen = {}
6369
},
6470
tables = {},
@@ -484,19 +490,9 @@ end
484490

485491
-- ---------------------------------------------------------------------------
486492

487-
local process_area = function(object, data)
488-
for _, func in ipairs(themepark.process.area) do
489-
if func(object, data) == 'stop' then
490-
return
491-
end
492-
end
493-
end
494-
495-
function osm2pgsql.process_node(object)
496-
local data = {}
497-
498-
for _, func in ipairs(themepark.process.node) do
499-
if func(object, data) == 'stop' then
493+
local call_each = function(funcs, ...)
494+
for _, func in ipairs(funcs) do
495+
if func(...) == 'stop' then
500496
return
501497
end
502498
end
@@ -505,30 +501,22 @@ end
505501
function osm2pgsql.process_way(object)
506502
local data = {}
507503

508-
for _, func in ipairs(themepark.process.way) do
509-
if func(object, data) == 'stop' then
510-
return
511-
end
512-
end
504+
call_each(themepark.process.way, object, data)
513505

514506
if themepark:way_is_area(object) then
515507
object.as_area = object.as_polygon
516-
process_area(object, data)
508+
call_each(themepark.process.area, object, data)
517509
end
518510
end
519511

520512
function osm2pgsql.process_relation(object)
521513
local data = {}
522514

523-
for _, func in ipairs(themepark.process.relation) do
524-
if func(object, data) == 'stop' then
525-
return
526-
end
527-
end
515+
call_each(themepark.process.relation, object, data)
528516

529517
if themepark:relation_is_area(object) then
530518
object.as_area = object.as_multipolygon
531-
process_area(object, data)
519+
call_each(themepark.process.area, object, data)
532520
end
533521
end
534522

@@ -551,16 +539,32 @@ function osm2pgsql.select_relation_members(relation)
551539
return members
552540
end
553541

554-
function osm2pgsql.process_gen()
555-
local data = {}
542+
local function gen_process_func_with_object(type)
543+
local funcs = themepark.process[type]
544+
return function(object)
545+
local data = {}
546+
call_each(funcs, object, data)
547+
end
548+
end
556549

557-
for _, func in ipairs(themepark.process.gen) do
558-
if func(data) == 'stop' then
559-
return
560-
end
550+
local function gen_process_func(type)
551+
local funcs = themepark.process[type]
552+
return function()
553+
local data = {}
554+
call_each(funcs, data)
561555
end
562556
end
563557

558+
osm2pgsql.process_node = gen_process_func_with_object('node')
559+
osm2pgsql.process_untagged_node = gen_process_func_with_object('untagged_node')
560+
osm2pgsql.process_untagged_way = gen_process_func_with_object('untagged_way')
561+
osm2pgsql.process_untagged_relation = gen_process_func_with_object('untagged_relation')
562+
563+
osm2pgsql.after_nodes = gen_process_func('after_nodes')
564+
osm2pgsql.after_ways = gen_process_func('after_ways')
565+
osm2pgsql.after_relations = gen_process_func('after_relations')
566+
osm2pgsql.process_gen = gen_process_func('gen')
567+
564568
-- ---------------------------------------------------------------------------
565569

566570
return themepark

0 commit comments

Comments
 (0)