@@ -16,6 +16,7 @@ bool geom_transform_point_t::is_compatible_with(
1616
1717geom::osmium_builder_t ::wkbs_t
1818geom_transform_point_t ::run(geom::osmium_builder_t *builder,
19+ table_column_type /* target_geom_type*/ ,
1920 osmium::Node const &node) const
2021{
2122 assert (builder);
@@ -49,6 +50,7 @@ bool geom_transform_line_t::is_compatible_with(
4950
5051geom::osmium_builder_t ::wkbs_t
5152geom_transform_line_t ::run(geom::osmium_builder_t *builder,
53+ table_column_type /* target_geom_type*/ ,
5254 osmium::Way *way) const
5355{
5456 assert (builder);
@@ -59,6 +61,7 @@ geom_transform_line_t::run(geom::osmium_builder_t *builder,
5961
6062geom::osmium_builder_t ::wkbs_t
6163geom_transform_line_t ::run(geom::osmium_builder_t *builder,
64+ table_column_type /* target_geom_type*/ ,
6265 osmium::Relation const & /* relation*/ ,
6366 osmium::memory::Buffer const &buffer) const
6467{
@@ -69,61 +72,77 @@ geom_transform_line_t::run(geom::osmium_builder_t *builder,
6972
7073bool geom_transform_area_t::set_param (char const *name, lua_State *lua_state)
7174{
72- 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 ) {
7382 return false ;
7483 }
7584
76- if (lua_type (lua_state, -1 ) != LUA_TBOOLEAN) {
85+ auto const val = lua_tostring (lua_state, -1 );
86+
87+ if (!val) {
7788 throw std::runtime_error{
78- " The 'multi ' field in a geometry transformation "
79- " description must be a boolean ." };
89+ " The 'split_at ' field in a geometry transformation "
90+ " description must be a string ." };
8091 }
81- m_multi = lua_toboolean (lua_state, -1 );
8292
83- 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)};
84100}
85101
86102bool geom_transform_area_t::is_compatible_with (
87103 table_column_type geom_type) const noexcept
88104{
89- if (m_multi) {
90- return geom_type == table_column_type::multipolygon ||
91- geom_type == table_column_type::geometry;
92- }
93-
94105 return geom_type == table_column_type::polygon ||
106+ geom_type == table_column_type::multipolygon ||
95107 geom_type == table_column_type::geometry;
96108}
97109
98110geom::osmium_builder_t ::wkbs_t
99111geom_transform_area_t ::run(geom::osmium_builder_t *builder,
112+ table_column_type target_geom_type,
100113 osmium::Way *way) const
101114{
102115 assert (builder);
103116 assert (way);
104117
118+ geom::osmium_builder_t ::wkbs_t result;
119+
105120 if (!way->is_closed ()) {
106- return {} ;
121+ return result ;
107122 }
108123
109- geom::osmium_builder_t ::wkbs_t result;
110124 result.push_back (builder->get_wkb_polygon (*way));
111125
112126 if (result.front ().empty ()) {
113127 result.clear ();
128+ } else if (target_geom_type == table_column_type::multipolygon) {
129+ builder->wrap_in_multipolygon (&result);
114130 }
115131
116132 return result;
117133}
118134
119135geom::osmium_builder_t ::wkbs_t
120136geom_transform_area_t ::run(geom::osmium_builder_t *builder,
137+ table_column_type target_geom_type,
121138 osmium::Relation const &relation,
122139 osmium::memory::Buffer const &buffer) const
123140{
124141 assert (builder);
125142
126- return builder->get_wkb_multipolygon (relation, buffer, m_multi);
143+ bool const wrap_multi = target_geom_type == table_column_type::multipolygon;
144+
145+ return builder->get_wkb_multipolygon (relation, buffer, m_multi, wrap_multi);
127146}
128147
129148std::unique_ptr<geom_transform_t > create_geom_transform (char const *type)
0 commit comments