Skip to content

Commit 39bdb89

Browse files
authored
Merge pull request #2160 from joto/replace-add-row-with-insert
Replace add_row() with insert() in tests
2 parents e82201c + 7acb80c commit 39bdb89

16 files changed

+188
-148
lines changed

Diff for: tests/bdd/flex/area.feature

+12-7
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,27 @@ Feature: Tests for area column type
2121
columns = {
2222
{ column = 'name', type = 'text' },
2323
{ column = 'geom', type = 'geometry', projection = <geom proj> },
24-
{ column = 'area', type = 'area', projection = <area proj> },
24+
{ column = 'area', type = 'real' },
2525
}
2626
}
2727
2828
function osm2pgsql.process_way(object)
29-
polygons:add_row({
29+
local geom = object:as_polygon()
30+
polygons:insert({
3031
name = object.tags.name,
31-
geom = { create = 'area' }
32+
geom = geom,
33+
area = geom:transform(<area proj>):area()
3234
})
3335
end
3436
3537
function osm2pgsql.process_relation(object)
36-
polygons:add_row({
37-
name = object.tags.name,
38-
geom = { create = 'area', split_at = 'multi' }
39-
})
38+
for sgeom in object:as_multipolygon():geometries() do
39+
polygons:insert({
40+
name = object.tags.name,
41+
geom = sgeom,
42+
area = sgeom:transform(<area proj>):area()
43+
})
44+
end
4045
end
4146
"""
4247
When running osm2pgsql flex

Diff for: tests/bdd/flex/bbox.feature

+12-9
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ Feature: Test get_bbox() function
1212
{ column = 'min_y', type = 'real' },
1313
{ column = 'max_x', type = 'real' },
1414
{ column = 'max_y', type = 'real' },
15-
{ column = 'geom', type = 'point', projection = <projection> },
15+
{ column = 'geom', type = 'point', projection = <projection>, not_null = true },
1616
})
1717
1818
function osm2pgsql.process_node(object)
19-
local row = {}
19+
local row = { geom = object:as_point() }
2020
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
21-
points:add_row(row)
21+
points:insert(row)
2222
end
2323
"""
2424
When running osm2pgsql flex
@@ -47,13 +47,13 @@ Feature: Test get_bbox() function
4747
{ column = 'min_y', type = 'real' },
4848
{ column = 'max_x', type = 'real' },
4949
{ column = 'max_y', type = 'real' },
50-
{ column = 'geom', type = 'linestring', projection = <projection> },
50+
{ column = 'geom', type = 'linestring', projection = <projection>, not_null = true },
5151
})
5252
5353
function osm2pgsql.process_way(object)
54-
local row = { geom = { create = 'line' } }
54+
local row = { geom = object:as_linestring() }
5555
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
56-
highways:add_row(row)
56+
highways:insert(row)
5757
end
5858
"""
5959
When running osm2pgsql flex
@@ -85,13 +85,16 @@ Feature: Test get_bbox() function
8585
{ column = 'min_y', type = 'real' },
8686
{ column = 'max_x', type = 'real' },
8787
{ column = 'max_y', type = 'real' },
88-
{ column = 'geom', type = 'linestring', projection = <projection> },
88+
{ column = 'geom', type = 'linestring', projection = <projection>, not_null = true },
8989
})
9090
9191
function osm2pgsql.process_relation(object)
92-
local row = { geom = { create = 'line' } }
92+
local row = {}
9393
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
94-
rels:add_row(row)
94+
for sgeom in object:as_multilinestring():line_merge():geometries() do
95+
row.geom = sgeom
96+
rels:insert(row)
97+
end
9598
end
9699
"""
97100
When running osm2pgsql flex

Diff for: tests/bdd/flex/extra-attributes.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Feature: Tests for including extra attributes
1414
{ column = 'timestamp', type = 'int4' },
1515
{ column = 'uid', type = 'int4' },
1616
{ column = 'user', type = 'text' },
17-
{ column = 'geom', type = 'linestring' },
17+
{ column = 'geom', type = 'linestring', not_null = true },
1818
}
1919
}
2020
2121
function osm2pgsql.process_way(object)
22-
object.geom = { create = 'line' }
23-
attr_table:add_row(object)
22+
object.geom = object:as_linestring()
23+
attr_table:insert(object)
2424
end
2525
"""
2626

Diff for: tests/bdd/flex/invalid-geometries.feature

+14-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Feature: Test handling of invalid geometries
1010
ids = { type = 'way', id_column = 'osm_id' },
1111
columns = {
1212
{ column = 'tags', type = 'hstore' },
13-
{ column = 'geom', type = 'linestring', projection = 4326 },
13+
{ column = 'geom', type = 'linestring', projection = 4326, not_null = true },
1414
}
1515
}
1616
@@ -19,28 +19,32 @@ Feature: Test handling of invalid geometries
1919
ids = { type = 'area', id_column = 'osm_id' },
2020
columns = {
2121
{ column = 'tags', type = 'hstore' },
22-
{ column = 'geom', type = 'geometry', projection = 4326 }
22+
{ column = 'geom', type = 'geometry', projection = 4326, not_null = true }
2323
}
2424
}
2525
2626
function osm2pgsql.process_way(object)
2727
if object.tags.natural then
28-
tables.polygon:add_row({
28+
tables.polygon:insert({
2929
tags = object.tags,
30-
geom = { create = 'area' }
30+
geom = object:as_polygon()
3131
})
3232
else
33-
tables.line:add_row({
34-
tags = object.tags
33+
tables.line:insert({
34+
tags = object.tags,
35+
geom = object:as_linestring()
3536
})
3637
end
3738
end
3839
3940
function osm2pgsql.process_relation(object)
40-
tables.polygon:add_row({
41-
tags = object.tags,
42-
geom = { create = 'area', split_at = 'multi' }
43-
})
41+
local mgeom = object:as_multipolygon()
42+
for sgeom in mgeom:geometries() do
43+
tables.polygon:insert({
44+
tags = object.tags,
45+
geom = sgeom
46+
})
47+
end
4448
end
4549
"""
4650

Diff for: tests/bdd/flex/line-splitting.feature

+10-8
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ Feature: Test splitting of lines
77
88
tables.line = osm2pgsql.define_way_table('osm2pgsql_test_line', {
99
{ column = 'tags', type = 'hstore' },
10-
{ column = 'geom', type = 'linestring', projection = 4326 }
10+
{ column = 'geom', type = 'linestring', projection = 4326, not_null = true }
1111
})
1212
1313
tables.split = osm2pgsql.define_way_table('osm2pgsql_test_split', {
1414
{ column = 'tags', type = 'hstore' },
15-
{ column = 'geom', type = 'linestring', projection = 4326 }
15+
{ column = 'geom', type = 'linestring', projection = 4326, not_null = true }
1616
})
1717
1818
function osm2pgsql.process_way(object)
19-
tables.line:add_row({
19+
tables.line:insert({
2020
tags = object.tags,
21-
geom = { create = 'line' }
22-
})
23-
tables.split:add_row({
24-
tags = object.tags,
25-
geom = { create = 'line', split_at = 1.0 }
21+
geom = object:as_linestring()
2622
})
23+
for sgeom in object:as_linestring():segmentize(1.0):geometries() do
24+
tables.split:insert({
25+
tags = object.tags,
26+
geom = sgeom
27+
})
28+
end
2729
end
2830
"""
2931

Diff for: tests/bdd/flex/multigeom.feature

+24-20
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ Feature: Handling of multiple geometries
2626
}
2727
2828
function osm2pgsql.process_way(object)
29-
polygons:add_row({
29+
polygons:insert({
3030
name = object.tags.name,
31-
geom = { create = 'area' }
31+
geom = object:as_polygon()
3232
})
3333
end
3434
3535
function osm2pgsql.process_relation(object)
36-
polygons:add_row({
36+
polygons:insert({
3737
name = object.tags.name,
38-
geom = { create = 'area' }
38+
geom = object:as_multipolygon()
3939
})
4040
end
4141
"""
@@ -61,17 +61,19 @@ Feature: Handling of multiple geometries
6161
}
6262
6363
function osm2pgsql.process_way(object)
64-
polygons:add_row({
64+
polygons:insert({
6565
name = object.tags.name,
66-
geom = { create = 'area' }
66+
geom = object:as_polygon()
6767
})
6868
end
6969
7070
function osm2pgsql.process_relation(object)
71-
polygons:add_row({
72-
name = object.tags.name,
73-
geom = { create = 'area', split_at = 'multi' }
74-
})
71+
for sgeom in object:as_multipolygon():geometries() do
72+
polygons:insert({
73+
name = object.tags.name,
74+
geom = sgeom
75+
})
76+
end
7577
end
7678
"""
7779
When running osm2pgsql flex
@@ -102,16 +104,16 @@ Feature: Handling of multiple geometries
102104
}
103105
104106
function osm2pgsql.process_way(object)
105-
polygons:add_row({
107+
polygons:insert({
106108
name = object.tags.name,
107-
geom = { create = 'area' }
109+
geom = object:as_polygon()
108110
})
109111
end
110112
111113
function osm2pgsql.process_relation(object)
112-
polygons:add_row({
114+
polygons:insert({
113115
name = object.tags.name,
114-
geom = { create = 'area' }
116+
geom = object:as_multipolygon()
115117
})
116118
end
117119
"""
@@ -137,17 +139,19 @@ Feature: Handling of multiple geometries
137139
}
138140
139141
function osm2pgsql.process_way(object)
140-
polygons:add_row({
142+
polygons:insert({
141143
name = object.tags.name,
142-
geom = { create = 'area' }
144+
geom = object:as_polygon()
143145
})
144146
end
145147
146148
function osm2pgsql.process_relation(object)
147-
polygons:add_row({
148-
name = object.tags.name,
149-
geom = { create = 'area', split_at = 'multi' }
150-
})
149+
for sgeom in object:as_multipolygon():geometries() do
150+
polygons:insert({
151+
name = object.tags.name,
152+
geom = sgeom
153+
})
154+
end
151155
end
152156
"""
153157
When running osm2pgsql flex

Diff for: tests/bdd/flex/nocluster.feature

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ Feature: Test flex config without clustering
77
"""
88
local dtable = osm2pgsql.define_node_table('osm2pgsql_test_point', {
99
{ column = 'tags', type = 'hstore' },
10-
{ column = 'geom', type = 'point' },
10+
{ column = 'geom', type = 'point', not_null = true },
1111
}, { cluster = 'no' })
1212
1313
function osm2pgsql.process_node(data)
14-
dtable:add_row({
15-
tags = data.tags
14+
dtable:insert({
15+
tags = data.tags,
16+
geom = data:as_point()
1617
})
1718
end
1819
"""

Diff for: tests/bdd/flex/nogeom.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Feature: Handling of tables without geometry
1313
})
1414
1515
function osm2pgsql.process_node(object)
16-
pois:add_row{ tags = object.tags }
16+
pois:insert{ tags = object.tags }
1717
end
1818
"""
1919
When running osm2pgsql flex with parameters

Diff for: tests/bdd/flex/relation-changes.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Feature: Handling changes to relations
55
"""
66
local rel_table = osm2pgsql.define_area_table('osm2pgsql_test_relations', {
77
{ column = 'tags', type = 'hstore' },
8-
{ column = 'geom', type = 'geometry' }
8+
{ column = 'geom', type = 'geometry', not_null = true }
99
})
1010
1111
function osm2pgsql.process_relation(object)
1212
if object.tags.type == 'multipolygon' then
13-
rel_table:add_row{
13+
rel_table:insert{
1414
tags = object.tags,
15-
geom = { create = 'area' }
15+
geom = object:as_multipolygon()
1616
}
1717
end
1818
end

0 commit comments

Comments
 (0)