Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove long deprecated add_row() Lua command #2166

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ if (WITH_LUA)
flex-lua-index.cpp
flex-lua-table.cpp
flex-write.cpp
geom-transform.cpp
lua-setup.cpp
lua-utils.cpp
output-flex.cpp
Expand Down
5 changes: 2 additions & 3 deletions src/flex-lua-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,11 @@ setup_flex_table_columns(lua_State *lua_state, flex_table_t *table,

lua_getfield(lua_state, -1, "projection");
if (!lua_isnil(lua_state, -1)) {
if (column.is_geometry_column() ||
column.type() == table_column_type::area) {
if (column.is_geometry_column()) {
column.set_projection(lua_tostring(lua_state, -1));
} else {
throw std::runtime_error{"Projection can only be set on "
"geometry and area columns."};
"geometry columns."};
}
}
lua_pop(lua_state, 1); // "projection"
Expand Down
9 changes: 0 additions & 9 deletions src/flex-table-column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ static std::array<column_type_lookup, 26> const column_types = {
{"multilinestring", table_column_type::multilinestring},
{"multipolygon", table_column_type::multipolygon},
{"geometrycollection", table_column_type::geometrycollection},
{"area", table_column_type::area},
{"id_type", table_column_type::id_type},
{"id_num", table_column_type::id_num}}};

Expand All @@ -62,12 +61,6 @@ static table_column_type get_column_type_from_string(std::string const &type)
throw fmt_error("Unknown column type '{}'.", type);
}

if (column_type->type == table_column_type::area) {
log_warn("The 'area' column type is deprecated. Please read");
log_warn("https://osm2pgsql.org/doc/tutorials/"
"switching-from-add-row-to-insert/");
}

return column_type->type;
}

Expand Down Expand Up @@ -167,8 +160,6 @@ std::string flex_table_column_t::sql_type_name() const
return fmt::format("Geometry(MULTIPOLYGON, {})", m_srid);
case table_column_type::geometrycollection:
return fmt::format("Geometry(GEOMETRYCOLLECTION, {})", m_srid);
case table_column_type::area:
return "real";
case table_column_type::id_type:
return "char(1)";
case table_column_type::id_num:
Expand Down
5 changes: 1 addition & 4 deletions src/flex-table-column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ enum class table_column_type : uint8_t
multipolygon,
geometrycollection,

area,

id_type,
id_num
};
Expand Down Expand Up @@ -158,8 +156,7 @@ class flex_table_column_t
table_column_type m_type;

/**
* For geometry and area columns only: The projection SRID. Default is
* web mercator.
* For geometry columns only: The projection SRID. Default is web mercator.
*/
int m_srid = 3857;

Expand Down
72 changes: 0 additions & 72 deletions src/flex-write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,6 @@ void flex_write_column(lua_State *lua_state,
flex_table_column_t const &column,
std::vector<expire_tiles> *expire)
{
// If there is nothing on the Lua stack, then the Lua function add_row()
// was called without a table parameter. In that case this column will
// be set to NULL.
if (lua_gettop(lua_state) == 0) {
write_null(copy_mgr, column);
return;
}

lua_getfield(lua_state, -1, column.name().c_str());
int const ltype = lua_type(lua_state, -1);

Expand Down Expand Up @@ -414,9 +406,6 @@ void flex_write_column(lua_State *lua_state,
lua_typename(lua_state, ltype));
}
} else if (column.is_geometry_column()) {
// If this is a geometry column, the Lua function 'insert()' was
// called, because for 'add_row()' geometry columns are handled
// earlier and 'write_column()' is not called.
if (ltype == LUA_TUSERDATA) {
auto const *const geom = unpack_geometry(lua_state, -1);
if (geom && !geom->is_null()) {
Expand Down Expand Up @@ -446,71 +435,10 @@ void flex_write_column(lua_State *lua_state,
throw fmt_error("Need geometry data for geometry column '{}'.",
column.name());
}
} else if (column.type() == table_column_type::area) {
// If this is an area column, the Lua function 'insert()' was
// called, because for 'add_row()' area columns are handled
// earlier and 'write_column()' is not called.
throw std::runtime_error{"Column type 'area' not allowed with "
"'insert()'. Maybe use 'real'?"};
} else {
throw fmt_error("Column type {} not implemented.",
static_cast<uint8_t>(column.type()));
}

lua_pop(lua_state, 1);
}

void flex_write_row(lua_State *lua_state, table_connection_t *table_connection,
osmium::item_type id_type, osmid_t id,
geom::geometry_t const &geom, int srid,
std::vector<expire_tiles> *expire)
{
assert(table_connection);
table_connection->new_line();
auto *copy_mgr = table_connection->copy_mgr();

geom::geometry_t projected_geom;
geom::geometry_t const *output_geom = &geom;
if (srid && geom.srid() != srid) {
projected_geom = geom::transform(geom, get_projection(srid));
output_geom = &projected_geom;
}

for (auto const &column : table_connection->table()) {
if (column.create_only()) {
continue;
}
if (column.type() == table_column_type::id_type) {
copy_mgr->add_column(type_to_char(id_type));
} else if (column.type() == table_column_type::id_num) {
copy_mgr->add_column(id);
} else if (column.is_geometry_column()) {
assert(!geom.is_null());
auto const type = column.type();
bool const wrap_multi =
(type == table_column_type::multilinestring ||
type == table_column_type::multipolygon);
copy_mgr->add_hex_geom(geom_to_ewkb(*output_geom, wrap_multi));
} else if (column.type() == table_column_type::area) {
if (geom.is_null()) {
write_null(copy_mgr, column);
} else {
// if srid of the area column is the same as for the geom column
double area = 0;
if (column.srid() == 4326) {
area = geom::area(geom);
} else if (column.srid() == srid) {
area = geom::area(projected_geom);
} else {
auto const &mproj = get_projection(column.srid());
area = geom::area(geom::transform(geom, mproj));
}
copy_mgr->add_column(area);
}
} else {
flex_write_column(lua_state, copy_mgr, column, expire);
}
}

copy_mgr->finish_line();
}
5 changes: 0 additions & 5 deletions src/flex-write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ void flex_write_column(lua_State *lua_state,
flex_table_column_t const &column,
std::vector<expire_tiles> *expire);

void flex_write_row(lua_State *lua_state, table_connection_t *table_connection,
osmium::item_type id_type, osmid_t id,
geom::geometry_t const &geom, int srid,
std::vector<expire_tiles> *expire);

#endif // OSM2PGSQL_FLEX_WRITE_HPP
Loading