Skip to content

Commit 947296a

Browse files
committed
Add osm2pgsql-expire command
New osm2pgsql-expire command that helps with debugging/visualizing expire tiles issues. The command can be used for two things: 1. To check what tiles some OSM data is in: If an OSM file is specified osm2pgsql-expire will calculate the tiles covering the objects in that file. Note that the file must not be a change file but a regular OSM data file! Output is, by default, a tile file, but GeoJSON is also possible. 2. Visualize tile list: If a tile file (presumably generated by osm2pgsql) is specified, a GeoJSON file is generated showing all mentioned tiles. In this mode all command line options are ignored.
1 parent 346ce16 commit 947296a

13 files changed

+708
-35
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ else()
271271
target_link_libraries(osm2pgsql-gen osm2pgsql_lib ${LIBS} ${POTRACE_LIBRARY} ${OpenCV_LIBS})
272272
endif()
273273

274+
add_executable(osm2pgsql-expire src/osm2pgsql-expire.cpp)
275+
target_link_libraries(osm2pgsql-expire osm2pgsql_lib ${LIBS})
276+
274277
#############################################################
275278
# Optional "clang-tidy" target
276279
#############################################################

man/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ if(PANDOC)
2626

2727
list(APPEND MANPAGE_TARGETS osm2pgsql.1)
2828

29+
add_custom_command(OUTPUT osm2pgsql-expire.1
30+
COMMAND ${PANDOC} ${PANDOC_MAN_OPTIONS} -o osm2pgsql-expire.1
31+
${CMAKE_CURRENT_SOURCE_DIR}/osm2pgsql-expire.md
32+
DEPENDS osm2pgsql-expire.md manpage.template
33+
COMMENT "Building manpage osm2pgsql-expire.1"
34+
VERBATIM)
35+
list(APPEND MANPAGE_TARGETS osm2pgsql-expire.1)
36+
2937
if(BUILD_GEN)
3038
add_custom_command(OUTPUT osm2pgsql-gen.1
3139
COMMAND ${PANDOC} ${PANDOC_MAN_OPTIONS} -o osm2pgsql-gen.1

man/osm2pgsql-expire.1

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
.TH "OSM2PGSQL" "1" "2.1.1" "" ""
2+
.SH NAME
3+
.PP
4+
osm2pgsql-expire - Visualize expire output
5+
.SH SYNOPSIS
6+
.PP
7+
\f[B]osm2pgsql-expire\f[R] [\f[I]OPTIONS\f[R]] \f[I]OSM-FILE\f[R] (1)
8+
\f[B]osm2pgsql-expire\f[R] \f[I]TILES-FILE\f[R] (2)
9+
.SH DESCRIPTION
10+
.PP
11+
\f[B]This command is currently experimental.\f[R]
12+
.PP
13+
The expire command can be used for two things:
14+
.IP "1." 3
15+
\f[B]To check what tiles some OSM data is in.\f[R] If an
16+
\f[I]OSM-FILE\f[R] is specified osm2pgsql-expire will calculate the
17+
tiles covering the objects in that file.
18+
Note that the file must not be a change file but a regular OSM data
19+
file!
20+
Output is, by default, a tile file, but GeoJSON is also possible.
21+
.IP "2." 3
22+
\f[B]Visualize tile list.\f[R] If a \f[I]TILE-FILE\f[R] (presumably
23+
generated by osm2pgsql) is specified, a GeoJSON file is generated
24+
showing all mentioned tiles.
25+
In this mode all command line options are ignored.
26+
.PP
27+
Read the \f[I]Expire\f[R] chapter of the osm2pgsql manual
28+
(https://osm2pgsql.org/doc/manual.html#expire) for details on how to
29+
interpret the \f[V]-m, \[rs]--mode\f[R] and
30+
\f[V]\[rs]--full-area-limit\f[R] options.
31+
.SH OPTIONS
32+
.PP
33+
This program follows the usual GNU command line syntax, with long
34+
options starting with two dashes (\f[V]--\f[R]).
35+
Mandatory arguments to long options are mandatory for short options too.
36+
.SH MAIN OPTIONS
37+
.TP
38+
-b, --buffer=VALUE
39+
Set buffer size around geometry relative to tile size.
40+
Example: Set to 0.1 for a buffer that\[cq]s 10% of the tile size.
41+
.TP
42+
-f, --format=FORMAT
43+
Output format.
44+
Options are `tiles' (default) or `geojson'.
45+
The GeoJSON output uses the Web Mercator projection (EPSG:3857) which is
46+
supported by many programs although, strictly speaking, it is not
47+
allowed by the GeoJSON spec.
48+
.TP
49+
--full-area-limit=VALUE
50+
Set full area limit.
51+
.TP
52+
-m, --mode=MODE
53+
Set expire mode.
54+
One of \f[V]boundary_only\f[R], \f[V]full_area\f[R] (default), and
55+
\f[V]hybrid\f[R].
56+
.TP
57+
-z, --zoom=ZOOM
58+
Zoom level on which to calculate tiles.
59+
.SH HELP/VERSION OPTIONS
60+
.TP
61+
-h, --help
62+
Print help.
63+
.TP
64+
-V, --version
65+
Print osm2pgsql version.
66+
.SH LOGGING OPTIONS
67+
.TP
68+
--log-level=LEVEL
69+
Set log level (`debug', `info' (default), `warn', or `error').
70+
.SH SEE ALSO
71+
.IP \[bu] 2
72+
osm2pgsql website (https://osm2pgsql.org)
73+
.IP \[bu] 2
74+
osm2pgsql manual (https://osm2pgsql.org/doc/manual.html)
75+
.IP \[bu] 2
76+
\f[B]osm2pgsql\f[R](1)
77+
.IP \[bu] 2
78+
\f[B]postgres\f[R](1)
79+
.IP \[bu] 2
80+
\f[B]osmcoastline\f[R](1)

man/osm2pgsql-expire.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# NAME
2+
3+
osm2pgsql-expire - Visualize expire output
4+
5+
# SYNOPSIS
6+
7+
**osm2pgsql-expire** \[*OPTIONS*\] *OSM-FILE* (1)
8+
**osm2pgsql-expire** *TILES-FILE* (2)
9+
10+
# DESCRIPTION
11+
12+
**This command is currently experimental.**
13+
14+
The expire command can be used for two things:
15+
16+
1. **To check what tiles some OSM data is in.** If an *OSM-FILE* is specified
17+
osm2pgsql-expire will calculate the tiles covering the objects in that file.
18+
Note that the file must not be a change file but a regular OSM data file!
19+
Output is, by default, a tile file, but GeoJSON is also possible.
20+
2. **Visualize tile list.** If a *TILE-FILE* (presumably generated by osm2pgsql)
21+
is specified, a GeoJSON file is generated showing all mentioned tiles. In
22+
this mode all command line options are ignored.
23+
24+
Read the *Expire* chapter of the osm2pgsql manual
25+
(https://osm2pgsql.org/doc/manual.html#expire) for details on how to
26+
interpret the `-m, \--mode` and `\--full-area-limit` options.
27+
28+
# OPTIONS
29+
30+
This program follows the usual GNU command line syntax, with long options
31+
starting with two dashes (`--`). Mandatory arguments to long options are
32+
mandatory for short options too.
33+
34+
# MAIN OPTIONS
35+
36+
-b, \--buffer=VALUE
37+
: Set buffer size around geometry relative to tile size. Example: Set to 0.1
38+
for a buffer that's 10% of the tile size.
39+
40+
-f, \--format=FORMAT
41+
: Output format. Options are 'tiles' (default) or 'geojson'. The GeoJSON output
42+
uses the Web Mercator projection (EPSG:3857) which is supported by many
43+
programs although, strictly speaking, it is not allowed by the GeoJSON spec.
44+
45+
\--full-area-limit=VALUE
46+
: Set full area limit.
47+
48+
-m, \--mode=MODE
49+
: Set expire mode. One of `boundary_only`, `full_area` (default), and `hybrid`.
50+
51+
-z, \--zoom=ZOOM
52+
: Zoom level on which to calculate tiles.
53+
54+
# HELP/VERSION OPTIONS
55+
56+
-h, \--help
57+
: Print help.
58+
59+
-V, \--version
60+
: Print osm2pgsql version.
61+
62+
# LOGGING OPTIONS
63+
64+
\--log-level=LEVEL
65+
: Set log level ('debug', 'info' (default), 'warn', or 'error').
66+
67+
# SEE ALSO
68+
69+
* [osm2pgsql website](https://osm2pgsql.org)
70+
* [osm2pgsql manual](https://osm2pgsql.org/doc/manual.html)
71+
* **osm2pgsql**(1)
72+
* **postgres**(1)
73+
* **osmcoastline**(1)
74+

src/command-line-app.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ command_line_app_t::command_line_app_t(std::string app_description)
2121

2222
add_flag("-h,--help", "Print this help message and exit.");
2323
add_flag("-V,--version", "Show version and exit.");
24-
25-
init_database_options();
26-
init_logging_options();
2724
}
2825

2926
bool command_line_app_t::want_help() const { return count("--help"); }
@@ -75,7 +72,7 @@ void command_line_app_t::init_database_options()
7572
->group("Database options");
7673
}
7774

78-
void command_line_app_t::init_logging_options()
75+
void command_line_app_t::init_logging_options(bool with_progress, bool with_sql)
7976
{
8077
static std::map<std::string, log_level> const log_levels_map{
8178
{"debug", log_level::debug},
@@ -97,31 +94,36 @@ void command_line_app_t::init_logging_options()
9794
->option_text("LEVEL")
9895
->group("Logging options");
9996

100-
add_option_function<std::string>(
101-
"--log-progress",
102-
[&](std::string const &arg) {
103-
if (arg == "true") {
104-
get_logger().enable_progress();
105-
} else if (arg == "false") {
106-
get_logger().disable_progress();
107-
} else if (arg == "auto") {
108-
get_logger().auto_progress();
109-
} else {
110-
throw fmt_error("Unknown value for --log-progress option: {}",
111-
arg);
112-
}
113-
})
114-
->description(
115-
"Log progress to console ('true', 'false', 'auto' (default)).")
116-
->option_text("PROGRESS")
117-
->group("Logging options");
118-
119-
add_flag_function("--log-sql", [](int64_t) { get_logger().enable_sql(); })
120-
->description("Enable logging of SQL commands for debugging.")
121-
->group("Logging options");
122-
123-
add_flag_function("--log-sql-data",
124-
[](int64_t) { get_logger().enable_sql_data(); })
125-
->description("Enable logging of all data added to the database.")
126-
->group("Logging options");
97+
if (with_progress) {
98+
add_option_function<std::string>(
99+
"--log-progress",
100+
[&](std::string const &arg) {
101+
if (arg == "true") {
102+
get_logger().enable_progress();
103+
} else if (arg == "false") {
104+
get_logger().disable_progress();
105+
} else if (arg == "auto") {
106+
get_logger().auto_progress();
107+
} else {
108+
throw fmt_error(
109+
"Unknown value for --log-progress option: {}", arg);
110+
}
111+
})
112+
->description(
113+
"Log progress to console ('true', 'false', 'auto' (default)).")
114+
->option_text("PROGRESS")
115+
->group("Logging options");
116+
}
117+
118+
if (with_sql) {
119+
add_flag_function("--log-sql",
120+
[](int64_t) { get_logger().enable_sql(); })
121+
->description("Enable logging of SQL commands for debugging.")
122+
->group("Logging options");
123+
124+
add_flag_function("--log-sql-data",
125+
[](int64_t) { get_logger().enable_sql_data(); })
126+
->description("Enable logging of all data added to the database.")
127+
->group("Logging options");
128+
}
127129
}

src/command-line-app.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class command_line_app_t : public CLI::App
3131
return m_connection_params;
3232
}
3333

34+
void init_database_options();
35+
void init_logging_options(bool with_progress, bool with_sql);
36+
3437
private:
3538
connection_params_t m_connection_params;
3639

37-
void init_database_options();
38-
void init_logging_options();
39-
4040
}; // class App
4141

4242
#endif // OSM2PGSQL_COMMAND_LINE_APP_HPP

src/command-line-parser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ options_t parse_command_line(int argc, char *argv[])
265265

266266
command_line_app_t app{"osm2pgsql -- Import OpenStreetMap data into a "
267267
"PostgreSQL/PostGIS database\n"};
268+
app.init_database_options();
269+
app.init_logging_options(true, true);
270+
268271
app.get_formatter()->column_width(38);
269272

270273
app.add_option("OSMFILE", options.input_files)

src/expire-output.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ std::size_t expire_output_t::output_tiles_to_file(
4545

4646
auto const count = for_each_tile(
4747
tiles_at_maxzoom, m_minzoom, m_maxzoom, [&](tile_t const &tile) {
48-
fmt::print(outfile, "{}/{}/{}\n", tile.zoom(), tile.x(), tile.y());
48+
fmt::print(outfile, "{}\n", tile.to_zxy());
4949
});
5050

5151
(void)std::fclose(outfile);

src/gen/osm2pgsql-gen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ int main(int argc, char *argv[])
646646

647647
command_line_app_t app{
648648
"osm2pgsql-gen -- Generalize OpenStreetMap data\n"};
649+
app.init_database_options();
650+
app.init_logging_options(true, true);
649651

650652
// ------------------------------------------------------------------
651653
// Main options

0 commit comments

Comments
 (0)