Skip to content

Commit a1283b2

Browse files
committed
Modernize compatible.lua example config
* Use insert()
1 parent e0153e3 commit a1283b2

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

flex-config/compatible.lua

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ function gen_columns(text_columns, with_hstore, area, geometry_type)
351351

352352
add_column('way', geometry_type)
353353
columns[#columns].projection = srid
354+
columns[#columns].not_null = true
354355

355356
return columns
356357
end
@@ -556,7 +557,18 @@ function osm2pgsql.process_node(object)
556557
output[hstore_column] = get_hstore_column(object.tags)
557558
end
558559

559-
tables.point:add_row(output)
560+
output.way = object:as_point()
561+
tables.point:insert(output)
562+
end
563+
564+
function add_line(output, geom, roads)
565+
for sgeom in geom:segmentize(max_length):geometries() do
566+
output.way = sgeom
567+
tables.line:insert(output)
568+
if roads then
569+
tables.roads:insert(output)
570+
end
571+
end
560572
end
561573

562574
function osm2pgsql.process_way(object)
@@ -617,14 +629,10 @@ function osm2pgsql.process_way(object)
617629
end
618630

619631
if polygon and object.is_closed then
620-
output.way = { create = 'area' }
621-
tables.polygon:add_row(output)
632+
output.way = object:as_polygon()
633+
tables.polygon:insert(output)
622634
else
623-
output.way = { create = 'line', split_at = max_length }
624-
tables.line:add_row(output)
625-
if roads then
626-
tables.roads:add_row(output)
627-
end
635+
add_line(output, object:as_linestring(), roads)
628636
end
629637
end
630638

@@ -718,19 +726,20 @@ function osm2pgsql.process_relation(object)
718726
end
719727

720728
if not make_polygon then
721-
output.way = { create = 'line', split_at = max_length }
722-
tables.line:add_row(output)
723-
if roads then
724-
tables.roads:add_row(output)
725-
end
729+
add_line(output, object:as_multilinestring(), roads)
726730
end
727731

728732
if make_boundary or make_polygon then
729-
output.way = { create = 'area' }
730-
if not multi_geometry then
731-
output.way.split_at = 'multi'
733+
local geom = object:as_multipolygon()
734+
if multi_geometry then
735+
output.way = geom
736+
tables.polygon:insert(output)
737+
else
738+
for sgeom in geom:geometries() do
739+
output.way = sgeom
740+
tables.polygon:insert(output)
741+
end
732742
end
733-
tables.polygon:add_row(output)
734743
end
735744
end
736745

0 commit comments

Comments
 (0)