Skip to content

Commit 3a3223c

Browse files
committed
Switch multipolygon generation from default off to default on
Also changes the name of the setting in the flex_config from multi=true/false to split_at=nil/'multi'.
1 parent c9747fd commit 3a3223c

15 files changed

Lines changed: 55 additions & 40 deletions

flex-config/compatible.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ local keep_coastlines = false
1414
-- Set this to the table name prefix (what used to be option -p|--prefix).
1515
local prefix = 'planet_osm'
1616

17-
-- Set this to true if multipolygons should be written as polygons into db
18-
-- (what used to be option -G|--multi-geometry).
17+
-- Set this to true if multipolygons should be written as multipolygons into
18+
-- db (what used to be option -G|--multi-geometry).
1919
local multi_geometry = false
2020

2121
-- Set this to true if you want an hstore column (what used to be option
@@ -724,7 +724,10 @@ function osm2pgsql.process_relation(object)
724724
end
725725

726726
if make_boundary or make_polygon then
727-
output.way = { create = 'area', multi = multi_geometry }
727+
output.way = { create = 'area' }
728+
if not multi_geometry then
729+
output.way.split_at = 'multi'
730+
end
728731
tables.polygon:add_row(output)
729732
end
730733
end

src/geom-transform.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,31 @@ geom_transform_line_t::run(geom::osmium_builder_t *builder,
7272

7373
bool geom_transform_area_t::set_param(char const *name, lua_State *lua_state)
7474
{
75-
if (std::strcmp(name, "multi") != 0) {
75+
if (std::strcmp(name, "multi") == 0) {
76+
throw std::runtime_error{
77+
"The 'multi' field in the geometry transformation has been"
78+
" removed. See docs on how to use 'split_at' instead."};
79+
}
80+
81+
if (std::strcmp(name, "split_at") != 0) {
7682
return false;
7783
}
7884

79-
if (lua_type(lua_state, -1) != LUA_TBOOLEAN) {
85+
auto const val = lua_tostring(lua_state, -1);
86+
87+
if (!val) {
8088
throw std::runtime_error{
81-
"The 'multi' field in a geometry transformation "
82-
"description must be a boolean."};
89+
"The 'split_at' field in a geometry transformation "
90+
"description must be a string."};
8391
}
84-
m_multi = lua_toboolean(lua_state, -1);
8592

86-
return true;
93+
if (std::strcmp(val, "multi") == 0) {
94+
m_multi = false;
95+
return true;
96+
}
97+
98+
throw std::runtime_error{"Unknown value for 'split_at' field in a geometry"
99+
" transformation: '{}'"_format(val)};
87100
}
88101

89102
bool geom_transform_area_t::is_compatible_with(

src/geom-transform.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class geom_transform_area_t : public geom_transform_t
108108
osmium::memory::Buffer const &buffer) const override;
109109

110110
private:
111-
bool m_multi = false;
111+
bool m_multi = true;
112112

113113
}; // class geom_transform_area_t
114114

tests/data/test_output_flex.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function osm2pgsql.process_relation(object)
117117
tables.polygon:add_row({
118118
tags = object.tags,
119119
name = object.tags.name,
120-
geom = { create = 'area', multi = false }
120+
geom = { create = 'area', split_at = 'multi' }
121121
})
122122
return
123123
end

tests/data/test_output_flex_area.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727
function osm2pgsql.process_relation(object)
2828
polygons:add_row({
2929
name = object.tags.name,
30-
geom = { create = 'area', multi = false }
30+
geom = { create = 'area', split_at = 'multi' }
3131
})
3232
end
3333

tests/data/test_output_flex_invalid_geom.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ end
3939
function osm2pgsql.process_relation(object)
4040
tables.polygon:add_row({
4141
tags = object.tags,
42-
geom = { create = 'area', multi = false }
42+
geom = { create = 'area', split_at = 'multi' }
4343
})
4444
end
4545

tests/data/test_output_flex_multigeom.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626
function osm2pgsql.process_relation(object)
2727
polygons:add_row({
2828
name = object.tags.name,
29-
geom = { create = 'area', multi = test.multi }
29+
geom = { create = 'area', split_at = test.split_at }
3030
})
3131
end
3232

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
test = { type = 'geometry', multi = true }
2+
test = { type = 'geometry' }
33

44
dofile(os.getenv('SRCPATH') .. '/data/test_output_flex_multigeom.lua')
55

tests/data/test_output_flex_multigeom_multipolygon_false.lua renamed to tests/data/test_output_flex_multigeom_geometry_split.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
test = { type = 'multipolygon', multi = false }
2+
test = { type = 'geometry', split_at = 'multi' }
33

44
dofile(os.getenv('SRCPATH') .. '/data/test_output_flex_multigeom.lua')
55

tests/data/test_output_flex_multigeom_geometry_false.lua renamed to tests/data/test_output_flex_multigeom_multipolygon.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
test = { type = 'geometry', multi = false }
2+
test = { type = 'multipolygon' }
33

44
dofile(os.getenv('SRCPATH') .. '/data/test_output_flex_multigeom.lua')
55

0 commit comments

Comments
 (0)