Skip to content

Commit b699cde

Browse files
committed
Remove long deprecated add_row() Lua command
This also removes the special "area" column type which was only used with the add_row() function.
1 parent 73c622b commit b699cde

12 files changed

+37
-674
lines changed

src/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ if (WITH_LUA)
6262
flex-lua-index.cpp
6363
flex-lua-table.cpp
6464
flex-write.cpp
65-
geom-transform.cpp
6665
lua-setup.cpp
6766
lua-utils.cpp
6867
output-flex.cpp

src/flex-lua-table.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,11 @@ setup_flex_table_columns(lua_State *lua_state, flex_table_t *table,
342342

343343
lua_getfield(lua_state, -1, "projection");
344344
if (!lua_isnil(lua_state, -1)) {
345-
if (column.is_geometry_column() ||
346-
column.type() == table_column_type::area) {
345+
if (column.is_geometry_column()) {
347346
column.set_projection(lua_tostring(lua_state, -1));
348347
} else {
349348
throw std::runtime_error{"Projection can only be set on "
350-
"geometry and area columns."};
349+
"geometry columns."};
351350
}
352351
}
353352
lua_pop(lua_state, 1); // "projection"

src/flex-table-column.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static std::array<column_type_lookup, 26> const column_types = {
5151
{"multilinestring", table_column_type::multilinestring},
5252
{"multipolygon", table_column_type::multipolygon},
5353
{"geometrycollection", table_column_type::geometrycollection},
54-
{"area", table_column_type::area},
5554
{"id_type", table_column_type::id_type},
5655
{"id_num", table_column_type::id_num}}};
5756

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

65-
if (column_type->type == table_column_type::area) {
66-
log_warn("The 'area' column type is deprecated. Please read");
67-
log_warn("https://osm2pgsql.org/doc/tutorials/"
68-
"switching-from-add-row-to-insert/");
69-
}
70-
7164
return column_type->type;
7265
}
7366

@@ -167,8 +160,6 @@ std::string flex_table_column_t::sql_type_name() const
167160
return fmt::format("Geometry(MULTIPOLYGON, {})", m_srid);
168161
case table_column_type::geometrycollection:
169162
return fmt::format("Geometry(GEOMETRYCOLLECTION, {})", m_srid);
170-
case table_column_type::area:
171-
return "real";
172163
case table_column_type::id_type:
173164
return "char(1)";
174165
case table_column_type::id_num:

src/flex-table-column.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ enum class table_column_type : uint8_t
4646
multipolygon,
4747
geometrycollection,
4848

49-
area,
50-
5149
id_type,
5250
id_num
5351
};
@@ -158,8 +156,7 @@ class flex_table_column_t
158156
table_column_type m_type;
159157

160158
/**
161-
* For geometry and area columns only: The projection SRID. Default is
162-
* web mercator.
159+
* For geometry columns only: The projection SRID. Default is web mercator.
163160
*/
164161
int m_srid = 3857;
165162

src/flex-write.cpp

-72
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,6 @@ void flex_write_column(lua_State *lua_state,
257257
flex_table_column_t const &column,
258258
std::vector<expire_tiles> *expire)
259259
{
260-
// If there is nothing on the Lua stack, then the Lua function add_row()
261-
// was called without a table parameter. In that case this column will
262-
// be set to NULL.
263-
if (lua_gettop(lua_state) == 0) {
264-
write_null(copy_mgr, column);
265-
return;
266-
}
267-
268260
lua_getfield(lua_state, -1, column.name().c_str());
269261
int const ltype = lua_type(lua_state, -1);
270262

@@ -414,9 +406,6 @@ void flex_write_column(lua_State *lua_state,
414406
lua_typename(lua_state, ltype));
415407
}
416408
} else if (column.is_geometry_column()) {
417-
// If this is a geometry column, the Lua function 'insert()' was
418-
// called, because for 'add_row()' geometry columns are handled
419-
// earlier and 'write_column()' is not called.
420409
if (ltype == LUA_TUSERDATA) {
421410
auto const *const geom = unpack_geometry(lua_state, -1);
422411
if (geom && !geom->is_null()) {
@@ -446,71 +435,10 @@ void flex_write_column(lua_State *lua_state,
446435
throw fmt_error("Need geometry data for geometry column '{}'.",
447436
column.name());
448437
}
449-
} else if (column.type() == table_column_type::area) {
450-
// If this is an area column, the Lua function 'insert()' was
451-
// called, because for 'add_row()' area columns are handled
452-
// earlier and 'write_column()' is not called.
453-
throw std::runtime_error{"Column type 'area' not allowed with "
454-
"'insert()'. Maybe use 'real'?"};
455438
} else {
456439
throw fmt_error("Column type {} not implemented.",
457440
static_cast<uint8_t>(column.type()));
458441
}
459442

460443
lua_pop(lua_state, 1);
461444
}
462-
463-
void flex_write_row(lua_State *lua_state, table_connection_t *table_connection,
464-
osmium::item_type id_type, osmid_t id,
465-
geom::geometry_t const &geom, int srid,
466-
std::vector<expire_tiles> *expire)
467-
{
468-
assert(table_connection);
469-
table_connection->new_line();
470-
auto *copy_mgr = table_connection->copy_mgr();
471-
472-
geom::geometry_t projected_geom;
473-
geom::geometry_t const *output_geom = &geom;
474-
if (srid && geom.srid() != srid) {
475-
projected_geom = geom::transform(geom, get_projection(srid));
476-
output_geom = &projected_geom;
477-
}
478-
479-
for (auto const &column : table_connection->table()) {
480-
if (column.create_only()) {
481-
continue;
482-
}
483-
if (column.type() == table_column_type::id_type) {
484-
copy_mgr->add_column(type_to_char(id_type));
485-
} else if (column.type() == table_column_type::id_num) {
486-
copy_mgr->add_column(id);
487-
} else if (column.is_geometry_column()) {
488-
assert(!geom.is_null());
489-
auto const type = column.type();
490-
bool const wrap_multi =
491-
(type == table_column_type::multilinestring ||
492-
type == table_column_type::multipolygon);
493-
copy_mgr->add_hex_geom(geom_to_ewkb(*output_geom, wrap_multi));
494-
} else if (column.type() == table_column_type::area) {
495-
if (geom.is_null()) {
496-
write_null(copy_mgr, column);
497-
} else {
498-
// if srid of the area column is the same as for the geom column
499-
double area = 0;
500-
if (column.srid() == 4326) {
501-
area = geom::area(geom);
502-
} else if (column.srid() == srid) {
503-
area = geom::area(projected_geom);
504-
} else {
505-
auto const &mproj = get_projection(column.srid());
506-
area = geom::area(geom::transform(geom, mproj));
507-
}
508-
copy_mgr->add_column(area);
509-
}
510-
} else {
511-
flex_write_column(lua_state, copy_mgr, column, expire);
512-
}
513-
}
514-
515-
copy_mgr->finish_line();
516-
}

src/flex-write.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,4 @@ void flex_write_column(lua_State *lua_state,
3636
flex_table_column_t const &column,
3737
std::vector<expire_tiles> *expire);
3838

39-
void flex_write_row(lua_State *lua_state, table_connection_t *table_connection,
40-
osmium::item_type id_type, osmid_t id,
41-
geom::geometry_t const &geom, int srid,
42-
std::vector<expire_tiles> *expire);
43-
4439
#endif // OSM2PGSQL_FLEX_WRITE_HPP

0 commit comments

Comments
 (0)