@@ -1002,84 +1002,6 @@ int output_flex_t::table_cluster()
10021002 return 1 ;
10031003}
10041004
1005- static std::unique_ptr<geom_transform_t >
1006- get_transform (lua_State *lua_state, flex_table_column_t const &column)
1007- {
1008- assert (lua_state);
1009- assert (lua_gettop (lua_state) == 1 );
1010-
1011- std::unique_ptr<geom_transform_t > transform{};
1012-
1013- lua_getfield (lua_state, -1 , column.name ().c_str ());
1014- int const ltype = lua_type (lua_state, -1 );
1015-
1016- // Field not set, return null transform
1017- if (ltype == LUA_TNIL) {
1018- lua_pop (lua_state, 1 ); // geom field
1019- return transform;
1020- }
1021-
1022- // Field set to anything but a Lua table is not allowed
1023- if (ltype != LUA_TTABLE) {
1024- lua_pop (lua_state, 1 ); // geom field
1025- throw std::runtime_error{
1026- " Invalid geometry transformation for column '{}'." _format (
1027- column.name ())};
1028- }
1029-
1030- lua_getfield (lua_state, -1 , " create" );
1031- char const *create_type = lua_tostring (lua_state, -1 );
1032- if (create_type == nullptr ) {
1033- throw std::runtime_error{
1034- " Missing geometry transformation for column '{}'." _format (
1035- column.name ())};
1036- }
1037-
1038- transform = create_geom_transform (create_type);
1039- lua_pop (lua_state, 1 ); // 'create' field
1040- init_geom_transform (transform.get (), lua_state);
1041- if (!transform->is_compatible_with (column.type ())) {
1042- throw std::runtime_error{
1043- " Geometry transformation is not compatible "
1044- " with column type '{}'." _format (column.type_name ())};
1045- }
1046-
1047- lua_pop (lua_state, 1 ); // geom field
1048-
1049- return transform;
1050- }
1051-
1052- static geom_transform_t const *
1053- get_default_transform (flex_table_column_t const &column,
1054- osmium::item_type object_type)
1055- {
1056- static geom_transform_point_t const default_transform_node_to_point{};
1057- static geom_transform_line_t const default_transform_way_to_line{};
1058- static geom_transform_area_t const default_transform_way_to_area{};
1059-
1060- switch (object_type) {
1061- case osmium::item_type::node:
1062- if (column.type () == table_column_type::point) {
1063- return &default_transform_node_to_point;
1064- }
1065- break ;
1066- case osmium::item_type::way:
1067- if (column.type () == table_column_type::linestring) {
1068- return &default_transform_way_to_line;
1069- }
1070- if (column.type () == table_column_type::polygon) {
1071- return &default_transform_way_to_area;
1072- }
1073- break ;
1074- default :
1075- break ;
1076- }
1077-
1078- throw std::runtime_error{
1079- " Missing geometry transformation for column '{}'." _format (
1080- column.name ())};
1081- }
1082-
10831005geom::geometry_t output_flex_t::run_transform (reprojection const &proj,
10841006 geom_transform_t const *transform,
10851007 osmium::Node const &node)
@@ -1140,18 +1062,17 @@ void output_flex_t::add_row(table_connection_t *table_connection,
11401062 " Need two parameters: The osm2pgsql.Table and the row data." };
11411063 }
11421064
1065+ auto const &proj = table_connection->proj ();
1066+ auto const type = table.geom_column ().type ();
1067+
11431068 auto const geom_transform = get_transform (lua_state (), table.geom_column ());
11441069 assert (lua_gettop (lua_state ()) == 1 );
11451070
11461071 geom_transform_t const *transform = geom_transform.get ();
1147-
11481072 if (!transform) {
11491073 transform = get_default_transform (table.geom_column (), object.type ());
11501074 }
11511075
1152- auto const &proj = table_connection->proj ();
1153- auto const type = table.geom_column ().type ();
1154-
11551076 // The geometry returned by run_transform() is in 4326 if it is a
11561077 // (multi)polygon. If it is a point or linestring, it is already in the
11571078 // target geometry.
0 commit comments