Skip to content

Commit 81a1dae

Browse files
authored
Merge pull request #1789 from joto/more-flex-config-updates
Update the rest of the flex example configs to new insert() syntax
2 parents d170a72 + 6403654 commit 81a1dae

File tree

6 files changed

+102
-280
lines changed

6 files changed

+102
-280
lines changed

flex-config/bbox.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ function osm2pgsql.process_node(object)
9595
return
9696
end
9797

98-
tables.pois:add_row({
98+
tables.pois:insert({
99+
tags = object.tags,
99100
bbox = format_bbox(object),
100-
tags = object.tags
101+
geom = object:as_point()
101102
})
102103
end
103104

@@ -108,16 +109,16 @@ function osm2pgsql.process_way(object)
108109

109110
-- A closed way that also has the right tags for an area is a polygon.
110111
if object.is_closed and has_area_tags(object.tags) then
111-
tables.polygons:add_row({
112+
tables.polygons:insert({
112113
tags = object.tags,
113114
bbox = format_bbox(object),
114-
geom = { create = 'area' }
115+
geom = object:as_polygon()
115116
})
116117
else
117-
tables.ways:add_row({
118+
tables.ways:insert({
118119
tags = object.tags,
119120
bbox = format_bbox(object),
120-
geom = { create = 'line' }
121+
geom = object:as_linestring()
121122
})
122123
end
123124
end
@@ -131,21 +132,21 @@ function osm2pgsql.process_relation(object)
131132

132133
-- Store boundary relations as multilinestrings
133134
if relation_type == 'boundary' then
134-
tables.boundaries:add_row({
135+
tables.boundaries:insert({
135136
type = object.tags.boundary,
136137
bbox = format_bbox(object),
137138
tags = object.tags,
138-
geom = { create = 'line' }
139+
geom = object:as_multilinestring()
139140
})
140141
return
141142
end
142143

143144
-- Store multipolygon relations as polygons
144145
if relation_type == 'multipolygon' then
145-
tables.polygons:add_row({
146+
tables.polygons:insert({
146147
bbox = format_bbox(object),
147148
tags = object.tags,
148-
geom = { create = 'area' }
149+
geom = object:as_multipolygon()
149150
})
150151
end
151152
end

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

flex-config/geometries-using-insert.lua

Lines changed: 0 additions & 202 deletions
This file was deleted.

0 commit comments

Comments
 (0)