Skip to content
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ else()
target_link_libraries(osm2pgsql-gen osm2pgsql_lib ${LIBS} ${POTRACE_LIBRARY} ${OpenCV_LIBS})
endif()

add_executable(osm2pgsql-expire src/osm2pgsql-expire.cpp)
target_link_libraries(osm2pgsql-expire osm2pgsql_lib ${LIBS})

#############################################################
# Optional "clang-tidy" target
#############################################################
Expand Down
8 changes: 8 additions & 0 deletions man/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ if(PANDOC)

list(APPEND MANPAGE_TARGETS osm2pgsql.1)

add_custom_command(OUTPUT osm2pgsql-expire.1
COMMAND ${PANDOC} ${PANDOC_MAN_OPTIONS} -o osm2pgsql-expire.1
${CMAKE_CURRENT_SOURCE_DIR}/osm2pgsql-expire.md
DEPENDS osm2pgsql-expire.md manpage.template
COMMENT "Building manpage osm2pgsql-expire.1"
VERBATIM)
list(APPEND MANPAGE_TARGETS osm2pgsql-expire.1)

if(BUILD_GEN)
add_custom_command(OUTPUT osm2pgsql-gen.1
COMMAND ${PANDOC} ${PANDOC_MAN_OPTIONS} -o osm2pgsql-gen.1
Expand Down
80 changes: 80 additions & 0 deletions man/osm2pgsql-expire.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.TH "OSM2PGSQL" "1" "2.1.1" "" ""
.SH NAME
.PP
osm2pgsql-expire - Visualize expire output
.SH SYNOPSIS
.PP
\f[B]osm2pgsql-expire\f[R] [\f[I]OPTIONS\f[R]] \f[I]OSM-FILE\f[R] (1)
\f[B]osm2pgsql-expire\f[R] \f[I]TILES-FILE\f[R] (2)
.SH DESCRIPTION
.PP
\f[B]This command is currently experimental.\f[R]
.PP
The expire command can be used for two things:
.IP "1." 3
\f[B]To check what tiles some OSM data is in.\f[R] If an
\f[I]OSM-FILE\f[R] 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.
.IP "2." 3
\f[B]Visualize tile list.\f[R] If a \f[I]TILE-FILE\f[R] (presumably
generated by osm2pgsql) is specified, a GeoJSON file is generated
showing all mentioned tiles.
In this mode all command line options are ignored.
.PP
Read the \f[I]Expire\f[R] chapter of the osm2pgsql manual
(https://osm2pgsql.org/doc/manual.html#expire) for details on how to
interpret the \f[V]-m, \[rs]--mode\f[R] and
\f[V]\[rs]--full-area-limit\f[R] options.
.SH OPTIONS
.PP
This program follows the usual GNU command line syntax, with long
options starting with two dashes (\f[V]--\f[R]).
Mandatory arguments to long options are mandatory for short options too.
.SH MAIN OPTIONS
.TP
-b, --buffer=VALUE
Set buffer size around geometry relative to tile size.
Example: Set to 0.1 for a buffer that\[cq]s 10% of the tile size.
.TP
-f, --format=FORMAT
Output format.
Options are `tiles' (default) or `geojson'.
The GeoJSON output uses the Web Mercator projection (EPSG:3857) which is
supported by many programs although, strictly speaking, it is not
allowed by the GeoJSON spec.
.TP
--full-area-limit=VALUE
Set full area limit.
.TP
-m, --mode=MODE
Set expire mode.
One of \f[V]boundary_only\f[R], \f[V]full_area\f[R] (default), and
\f[V]hybrid\f[R].
.TP
-z, --zoom=ZOOM
Zoom level on which to calculate tiles.
.SH HELP/VERSION OPTIONS
.TP
-h, --help
Print help.
.TP
-V, --version
Print osm2pgsql version.
.SH LOGGING OPTIONS
.TP
--log-level=LEVEL
Set log level (`debug', `info' (default), `warn', or `error').
.SH SEE ALSO
.IP \[bu] 2
osm2pgsql website (https://osm2pgsql.org)
.IP \[bu] 2
osm2pgsql manual (https://osm2pgsql.org/doc/manual.html)
.IP \[bu] 2
\f[B]osm2pgsql\f[R](1)
.IP \[bu] 2
\f[B]postgres\f[R](1)
.IP \[bu] 2
\f[B]osmcoastline\f[R](1)
74 changes: 74 additions & 0 deletions man/osm2pgsql-expire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# NAME

osm2pgsql-expire - Visualize expire output

# SYNOPSIS

**osm2pgsql-expire** \[*OPTIONS*\] *OSM-FILE* (1)
**osm2pgsql-expire** *TILES-FILE* (2)

# DESCRIPTION

**This command is currently experimental.**

The expire 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.

Read the *Expire* chapter of the osm2pgsql manual
(https://osm2pgsql.org/doc/manual.html#expire) for details on how to
interpret the `-m, \--mode` and `\--full-area-limit` options.

# OPTIONS

This program follows the usual GNU command line syntax, with long options
starting with two dashes (`--`). Mandatory arguments to long options are
mandatory for short options too.

# MAIN OPTIONS

-b, \--buffer=VALUE
: Set buffer size around geometry relative to tile size. Example: Set to 0.1
for a buffer that's 10% of the tile size.

-f, \--format=FORMAT
: Output format. Options are 'tiles' (default) or 'geojson'. The GeoJSON output
uses the Web Mercator projection (EPSG:3857) which is supported by many
programs although, strictly speaking, it is not allowed by the GeoJSON spec.

\--full-area-limit=VALUE
: Set full area limit.

-m, \--mode=MODE
: Set expire mode. One of `boundary_only`, `full_area` (default), and `hybrid`.

-z, \--zoom=ZOOM
: Zoom level on which to calculate tiles.

# HELP/VERSION OPTIONS

-h, \--help
: Print help.

-V, \--version
: Print osm2pgsql version.

# LOGGING OPTIONS

\--log-level=LEVEL
: Set log level ('debug', 'info' (default), 'warn', or 'error').

# SEE ALSO

* [osm2pgsql website](https://osm2pgsql.org)
* [osm2pgsql manual](https://osm2pgsql.org/doc/manual.html)
* **osm2pgsql**(1)
* **postgres**(1)
* **osmcoastline**(1)

64 changes: 33 additions & 31 deletions src/command-line-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ command_line_app_t::command_line_app_t(std::string app_description)

add_flag("-h,--help", "Print this help message and exit.");
add_flag("-V,--version", "Show version and exit.");

init_database_options();
init_logging_options();
}

bool command_line_app_t::want_help() const { return count("--help"); }
Expand Down Expand Up @@ -75,7 +72,7 @@ void command_line_app_t::init_database_options()
->group("Database options");
}

void command_line_app_t::init_logging_options()
void command_line_app_t::init_logging_options(bool with_progress, bool with_sql)
{
static std::map<std::string, log_level> const log_levels_map{
{"debug", log_level::debug},
Expand All @@ -97,31 +94,36 @@ void command_line_app_t::init_logging_options()
->option_text("LEVEL")
->group("Logging options");

add_option_function<std::string>(
"--log-progress",
[&](std::string const &arg) {
if (arg == "true") {
get_logger().enable_progress();
} else if (arg == "false") {
get_logger().disable_progress();
} else if (arg == "auto") {
get_logger().auto_progress();
} else {
throw fmt_error("Unknown value for --log-progress option: {}",
arg);
}
})
->description(
"Log progress to console ('true', 'false', 'auto' (default)).")
->option_text("PROGRESS")
->group("Logging options");

add_flag_function("--log-sql", [](int64_t) { get_logger().enable_sql(); })
->description("Enable logging of SQL commands for debugging.")
->group("Logging options");

add_flag_function("--log-sql-data",
[](int64_t) { get_logger().enable_sql_data(); })
->description("Enable logging of all data added to the database.")
->group("Logging options");
if (with_progress) {
add_option_function<std::string>(
"--log-progress",
[&](std::string const &arg) {
if (arg == "true") {
get_logger().enable_progress();
} else if (arg == "false") {
get_logger().disable_progress();
} else if (arg == "auto") {
get_logger().auto_progress();
} else {
throw fmt_error(
"Unknown value for --log-progress option: {}", arg);
}
})
->description(
"Log progress to console ('true', 'false', 'auto' (default)).")
->option_text("PROGRESS")
->group("Logging options");
}

if (with_sql) {
add_flag_function("--log-sql",
[](int64_t) { get_logger().enable_sql(); })
->description("Enable logging of SQL commands for debugging.")
->group("Logging options");

add_flag_function("--log-sql-data",
[](int64_t) { get_logger().enable_sql_data(); })
->description("Enable logging of all data added to the database.")
->group("Logging options");
}
}
6 changes: 3 additions & 3 deletions src/command-line-app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class command_line_app_t : public CLI::App
return m_connection_params;
}

void init_database_options();
void init_logging_options(bool with_progress, bool with_sql);

private:
connection_params_t m_connection_params;

void init_database_options();
void init_logging_options();

}; // class App

#endif // OSM2PGSQL_COMMAND_LINE_APP_HPP
3 changes: 3 additions & 0 deletions src/command-line-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ options_t parse_command_line(int argc, char *argv[])

command_line_app_t app{"osm2pgsql -- Import OpenStreetMap data into a "
"PostgreSQL/PostGIS database\n"};
app.init_database_options();
app.init_logging_options(true, true);

app.get_formatter()->column_width(38);

app.add_option("OSMFILE", options.input_files)
Expand Down
2 changes: 1 addition & 1 deletion src/expire-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::size_t expire_output_t::output_tiles_to_file(

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

(void)std::fclose(outfile);
Expand Down
2 changes: 2 additions & 0 deletions src/gen/osm2pgsql-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ int main(int argc, char *argv[])

command_line_app_t app{
"osm2pgsql-gen -- Generalize OpenStreetMap data\n"};
app.init_database_options();
app.init_logging_options(true, true);

// ------------------------------------------------------------------
// Main options
Expand Down
Loading