Skip to content

Commit bfc672b

Browse files
committed
Rename "tileset" to "expire output" in code and Lua config
The new better reflects what this is.
1 parent 90ad02a commit bfc672b

18 files changed

+381
-352
lines changed
Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
-- This config example file is released into the Public Domain.
22
--
3-
-- This examples shows how to use tilesets for expire.
3+
-- This examples shows how to use tile expiry.
44

5-
local tilesets = {}
5+
local expire_outputs = {}
66

7-
tilesets.pois = osm2pgsql.define_tileset({
8-
-- Every tileset must have a name. The name is independent of the table
9-
-- names although this example file uses the same name for simplicity.
7+
expire_outputs.pois = osm2pgsql.define_expire_output({
8+
-- Every expire output must have a name. The name is independent of the
9+
-- data table names although this example file uses the same name for
10+
-- simplicity.
1011
name = 'pois',
1112
-- The zoom level at which we calculate the tiles. This must always be set.
1213
maxzoom = 14,
1314
-- The filename where tile list should be written to.
1415
filename = 'pois.tiles'
1516
})
1617

17-
tilesets.lines = osm2pgsql.define_tileset({
18+
expire_outputs.lines = osm2pgsql.define_expire_output({
1819
name = 'lines',
1920
maxzoom = 14,
2021
-- Instead of writing the tile list to a file, it can be written to a table.
@@ -23,7 +24,7 @@ tilesets.lines = osm2pgsql.define_tileset({
2324
-- schema = 'myschema', -- You can also set a database schema.
2425
})
2526

26-
tilesets.polygons = osm2pgsql.define_tileset({
27+
expire_outputs.polygons = osm2pgsql.define_expire_output({
2728
name = 'polygons',
2829
-- You can also set a minimum zoom level in addition to the maximum zoom
2930
-- level. Tiles in all zoom levels between those two will be written out.
@@ -32,33 +33,33 @@ tilesets.polygons = osm2pgsql.define_tileset({
3233
table = 'polygons_tiles'
3334
})
3435

35-
print("Tilesets:(")
36-
for name, ts in pairs(tilesets) do
36+
print("Expire outputs:(")
37+
for name, eo in pairs(expire_outputs) do
3738
print(" " .. name
38-
.. ": name=".. ts:name()
39-
.. " minzoom=" .. ts:minzoom()
40-
.. " maxzoom=" .. ts:maxzoom()
41-
.. " filename=" .. ts:filename()
42-
.. " schema=" .. ts:schema()
43-
.. " table=" .. ts:table()
44-
.. " (" .. tostring(ts) .. ")")
39+
.. ": name=".. eo:name()
40+
.. " minzoom=" .. eo:minzoom()
41+
.. " maxzoom=" .. eo:maxzoom()
42+
.. " filename=" .. eo:filename()
43+
.. " schema=" .. eo:schema()
44+
.. " table=" .. eo:table()
45+
.. " (" .. tostring(eo) .. ")")
4546
end
4647
print(")")
4748

4849
local tables = {}
4950

5051
tables.pois = osm2pgsql.define_node_table('pois', {
5152
{ column = 'tags', type = 'jsonb' },
52-
-- Zero, one or more tilesets are referenced in an `expire` field in
53+
-- Zero, one or more expire outputs are referenced in an `expire` field in
5354
-- the definition of any geometry column using the Web Mercator (3857)
5455
-- projection.
55-
{ column = 'geom', type = 'point', not_null = true, expire = { { tileset = 'pois' } } },
56+
{ column = 'geom', type = 'point', not_null = true, expire = { { output = 'pois' } } },
5657
})
5758

5859
tables.lines = osm2pgsql.define_way_table('lines', {
5960
{ column = 'tags', type = 'jsonb' },
60-
-- If you only have a single tileset you want to expire into and with
61-
-- the defalt parameters, you can specify it directly.
61+
-- If you only have a single expire output and with the default
62+
-- parameters, you can specify it directly.
6263
{ column = 'geom', type = 'linestring', not_null = true, expire = 'lines' },
6364
})
6465

@@ -70,7 +71,9 @@ tables.polygons = osm2pgsql.define_area_table('polygons', {
7071
-- polygons where the width and height of the bounding box is below this
7172
-- limit the full area is expired, for larger polygons only the boundary.
7273
-- This setting doesn't have any effect on point or linestring geometries.
73-
{ column = 'geom', type = 'geometry', not_null = true, expire = { { tileset = 'polygons', mode = 'boundary-only' } } },
74+
{ column = 'geom', type = 'geometry', not_null = true, expire = {
75+
{ output = 'polygons', mode = 'boundary-only' }
76+
}}
7477
})
7578

7679
tables.boundaries = osm2pgsql.define_relation_table('boundaries', {

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ if (WITH_LUA)
4747
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/init.lua" LUA_INIT_CODE)
4848
configure_file(lua-init.cpp.in lua-init.cpp @ONLY)
4949
target_sources(osm2pgsql_lib PRIVATE
50+
expire-output.cpp
5051
flex-index.cpp
5152
flex-table.cpp
5253
flex-table-column.cpp
53-
flex-tileset.cpp
54+
flex-lua-expire-output.cpp
5455
flex-lua-geom.cpp
5556
flex-lua-index.cpp
5657
flex-lua-table.cpp
57-
flex-lua-tileset.cpp
5858
flex-write.cpp
5959
geom-transform.cpp
6060
lua-utils.cpp

src/expire-config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ enum class expire_mode
2525
struct expire_config_t
2626
{
2727
/**
28-
* The id of the tile set where expired tiles are collected.
28+
* The id of the expire output to which expired tiles are written.
2929
* Only used in the flex output.
3030
*/
31-
std::size_t tileset = 0;
31+
std::size_t expire_output = 0;
3232

3333
/// Buffer around expired feature as fraction of the tile size.
3434
double buffer = 0.1;
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
* For a full list of authors see the git log.
88
*/
99

10+
#include "expire-output.hpp"
11+
1012
#include "expire-tiles.hpp"
11-
#include "flex-tileset.hpp"
13+
#include "tile.hpp"
1214

13-
std::size_t flex_tileset_t::output(quadkey_list_t const &tile_list,
14-
std::string const &conninfo) const
15+
std::size_t expire_output_t::output(quadkey_list_t const &tile_list,
16+
std::string const &conninfo) const
1517
{
1618
std::size_t num = 0;
1719
if (!m_filename.empty()) {
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OSM2PGSQL_FLEX_TILESET_HPP
2-
#define OSM2PGSQL_FLEX_TILESET_HPP
1+
#ifndef OSM2PGSQL_EXPIRE_OUTPUT_HPP
2+
#define OSM2PGSQL_EXPIRE_OUTPUT_HPP
33

44
/**
55
* SPDX-License-Identifier: GPL-2.0-or-later
@@ -14,15 +14,14 @@
1414

1515
#include <string>
1616
#include <utility>
17-
#include <vector>
1817

1918
/**
20-
* A tileset for the flex output. Used for expire.
19+
* Output for tile expiry.
2120
*/
22-
class flex_tileset_t
21+
class expire_output_t
2322
{
2423
public:
25-
explicit flex_tileset_t(std::string name) : m_name(std::move(name)) {}
24+
explicit expire_output_t(std::string name) : m_name(std::move(name)) {}
2625

2726
std::string const &name() const noexcept { return m_name; }
2827

@@ -53,7 +52,7 @@ class flex_tileset_t
5352
std::string const &conninfo) const;
5453

5554
private:
56-
/// The name of the tileset
55+
/// The internal (unique) name of the output
5756
std::string m_name;
5857

5958
/// The filename (if any) for output
@@ -71,6 +70,6 @@ class flex_tileset_t
7170
/// Zoom level we capture tiles on
7271
uint32_t m_maxzoom = 0;
7372

74-
}; // class flex_tileset_t
73+
}; // class expire_output_t
7574

76-
#endif // OSM2PGSQL_FLEX_TILESET_HPP
75+
#endif // OSM2PGSQL_EXPIRE_OUTPUT_HPP

src/flex-lua-expire-output.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* SPDX-License-Identifier: GPL-2.0-or-later
3+
*
4+
* This file is part of osm2pgsql (https://osm2pgsql.org/).
5+
*
6+
* Copyright (C) 2006-2023 by the osm2pgsql developer community.
7+
* For a full list of authors see the git log.
8+
*/
9+
10+
#include "flex-lua-expire-output.hpp"
11+
12+
#include "expire-output.hpp"
13+
#include "format.hpp"
14+
#include "lua-utils.hpp"
15+
#include "pgsql.hpp"
16+
#include "util.hpp"
17+
18+
#include <lua.hpp>
19+
20+
static expire_output_t &
21+
create_expire_output(lua_State *lua_state,
22+
std::vector<expire_output_t> *expire_outputs)
23+
{
24+
std::string const expire_output_name =
25+
luaX_get_table_string(lua_state, "name", -1, "The expire output");
26+
27+
check_identifier(expire_output_name, "expire output names");
28+
29+
if (util::find_by_name(*expire_outputs, expire_output_name)) {
30+
throw fmt_error("Expire output with name '{}' already exists.",
31+
expire_output_name);
32+
}
33+
34+
auto &new_expire_output = expire_outputs->emplace_back(expire_output_name);
35+
36+
lua_pop(lua_state, 1); // "name"
37+
38+
// optional "filename" field
39+
auto const *filename = luaX_get_table_string(lua_state, "filename", -1,
40+
"The expire output", "");
41+
new_expire_output.set_filename(filename);
42+
lua_pop(lua_state, 1); // "filename"
43+
44+
// optional "schema" and "table" fields
45+
auto const *schema =
46+
luaX_get_table_string(lua_state, "schema", -1, "The expire output", "");
47+
check_identifier(schema, "schema field");
48+
auto const *table =
49+
luaX_get_table_string(lua_state, "table", -2, "The expire output", "");
50+
check_identifier(table, "table field");
51+
new_expire_output.set_schema_and_table(schema, table);
52+
lua_pop(lua_state, 2); // "schema" and "table"
53+
54+
if (new_expire_output.filename().empty() &&
55+
new_expire_output.table().empty()) {
56+
throw fmt_error(
57+
"Must set 'filename' and/or 'table' on expire output '{}'.",
58+
new_expire_output.name());
59+
}
60+
61+
// required "maxzoom" field
62+
auto value = luaX_get_table_optional_uint32(
63+
lua_state, "maxzoom", -1, "The 'maxzoom' field in a expire output");
64+
if (value >= 1 && value <= 20) {
65+
new_expire_output.set_minzoom(value);
66+
new_expire_output.set_maxzoom(value);
67+
} else {
68+
throw std::runtime_error{
69+
"Value of 'maxzoom' field must be between 1 and 20."};
70+
}
71+
lua_pop(lua_state, 1); // "maxzoom"
72+
73+
// optional "minzoom" field
74+
value = luaX_get_table_optional_uint32(
75+
lua_state, "minzoom", -1, "The 'minzoom' field in a expire output");
76+
if (value >= 1 && value <= new_expire_output.maxzoom()) {
77+
new_expire_output.set_minzoom(value);
78+
} else if (value != 0) {
79+
throw std::runtime_error{
80+
"Value of 'minzoom' field must be between 1 and 'maxzoom'."};
81+
}
82+
lua_pop(lua_state, 1); // "minzoom"
83+
84+
return new_expire_output;
85+
}
86+
87+
int setup_flex_expire_output(lua_State *lua_state,
88+
std::vector<expire_output_t> *expire_outputs)
89+
{
90+
if (lua_type(lua_state, 1) != LUA_TTABLE) {
91+
throw std::runtime_error{
92+
"Argument #1 to 'define_expire_output' must be a Lua table."};
93+
}
94+
95+
create_expire_output(lua_state, expire_outputs);
96+
97+
void *ptr = lua_newuserdata(lua_state, sizeof(std::size_t));
98+
auto *num = new (ptr) std::size_t{};
99+
*num = expire_outputs->size() - 1;
100+
luaL_getmetatable(lua_state, osm2pgsql_expire_output_name);
101+
lua_setmetatable(lua_state, -2);
102+
103+
return 1;
104+
}

src/flex-lua-expire-output.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef OSM2PGSQL_FLEX_LUA_EXPIRE_OUTPUT_HPP
2+
#define OSM2PGSQL_FLEX_LUA_EXPIRE_OUTPUT_HPP
3+
4+
/**
5+
* SPDX-License-Identifier: GPL-2.0-or-later
6+
*
7+
* This file is part of osm2pgsql (https://osm2pgsql.org/).
8+
*
9+
* Copyright (C) 2006-2023 by the osm2pgsql developer community.
10+
* For a full list of authors see the git log.
11+
*/
12+
13+
#include "expire-output.hpp"
14+
15+
#include <vector>
16+
17+
struct lua_State;
18+
19+
static char const *const osm2pgsql_expire_output_name =
20+
"osm2pgsql.ExpireOutput";
21+
22+
int setup_flex_expire_output(lua_State *lua_state,
23+
std::vector<expire_output_t> *expire_outputs);
24+
25+
#endif // OSM2PGSQL_FLEX_LUA_EXPIRE_OUTPUT_HPP

0 commit comments

Comments
 (0)