From 3984965378b8eb7eff5c3483f5dc4a71080967ed Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Mon, 27 Oct 2025 15:05:38 +0100 Subject: [PATCH] osm2pgsql-expire: Expire type=boundary relations as multipolygons You can always use --mode=boundary_only to switch back to boundary only interepretation. So type=boundary is now treated exactly like type=multipolygon. Also adds more information to man page. --- man/osm2pgsql-expire.1 | 75 ++++++++++++++++++++++++++-------------- man/osm2pgsql-expire.md | 22 +++++++++++- src/osm2pgsql-expire.cpp | 2 +- 3 files changed, 71 insertions(+), 28 deletions(-) diff --git a/man/osm2pgsql-expire.1 b/man/osm2pgsql-expire.1 index c6dbd023c..5425c3fa2 100644 --- a/man/osm2pgsql-expire.1 +++ b/man/osm2pgsql-expire.1 @@ -1,79 +1,102 @@ .TH "OSM2PGSQL" "1" "2.2.0" "" "" .SH NAME -osm2pgsql\-expire \- Visualize expire output +.PP +osm2pgsql-expire - Visualize expire output .SH SYNOPSIS -\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) +.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 +\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. +Covering tiles are only calculated for tagged objects. .IP "2." 3 -\f[B]Visualize tile list.\f[R] If a \f[I]TILE\-FILE\f[R] (presumably +\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[CR]\-m, \[rs]\-\-mode\f[R] and -\f[CR]\[rs]\-\-full\-area\-limit\f[R] options. +interpret the \f[V]-m, \[rs]--mode\f[R] and +\f[V]\[rs]--full-area-limit\f[R] options. +.SH GEOMETRY GENERATION +.PP +To calculate the tiles covering the specified OSM data in mode (1), a +geometry has to be generated first for each object. +This works as follow: +.IP \[bu] 2 +For nodes a point geometry will be generated. +.IP \[bu] 2 +For closed ways a polygon geometry will be generated, for non-closed +ways a linestring geometry. +If a generated polygon is not valid, the program will fall back to a +linestring. +If neither a valid polygon nor a valid linestring can be generated the +object is ignored. +.IP \[bu] 2 +For relations a geometry is generated based on the \f[V]type\f[R] tag. +For types \f[V]multipolygon\f[R] and \f[V]boundary\f[R], a multipolygon +geometry is created, for types \f[V]route\f[R] and +\f[V]multilinestring\f[R] a multilinestring geometry is created, for all +other types a geometry collection is created. +.PP +Note that for (multi)polygons it depends on the command line options +--mode and --full-area-limit whether the tiles calculation is based on +the area or the boundary of the (multi)polygons. .SH OPTIONS +.PP This program follows the usual GNU command line syntax, with long -options starting with two dashes (\f[CR]\-\-\f[R]). +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 +-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 +-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 +--full-area-limit=VALUE Set full area limit. .TP -\-m, \-\-mode=MODE +-m, --mode=MODE Set expire mode. -One of \f[CR]boundary_only\f[R], \f[CR]full_area\f[R] (default), and -\f[CR]hybrid\f[R]. +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 +-z, --zoom=ZOOM Zoom level on which to calculate tiles. .SH HELP/VERSION OPTIONS .TP -\-h, \-\-help +-h, --help Print help. .TP -\-V, \-\-version +-V, --version Print osm2pgsql version. .SH LOGGING OPTIONS .TP -\-\-log\-level=LEVEL +--log-level=LEVEL Set log level (`debug', `info' (default), `warn', or `error'). .SH SEE ALSO .IP \[bu] 2 -\c -.UR https://osm2pgsql.org -osm2pgsql website -.UE \c +osm2pgsql website (https://osm2pgsql.org) .IP \[bu] 2 -\c -.UR https://osm2pgsql.org/doc/manual.html -osm2pgsql manual -.UE \c +osm2pgsql manual (https://osm2pgsql.org/doc/manual.html) .IP \[bu] 2 \f[B]osm2pgsql\f[R](1) .IP \[bu] 2 diff --git a/man/osm2pgsql-expire.md b/man/osm2pgsql-expire.md index 3024b81b0..9c031ee5b 100644 --- a/man/osm2pgsql-expire.md +++ b/man/osm2pgsql-expire.md @@ -16,7 +16,8 @@ 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. + Output is, by default, a tile file, but GeoJSON is also possible. Covering + tiles are only calculated for tagged objects. 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. @@ -25,6 +26,25 @@ 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. +# GEOMETRY GENERATION + +To calculate the tiles covering the specified OSM data in mode (1), a geometry +has to be generated first for each object. This works as follow: + +* For nodes a point geometry will be generated. +* For closed ways a polygon geometry will be generated, for non-closed ways + a linestring geometry. If a generated polygon is not valid, the program + will fall back to a linestring. If neither a valid polygon nor a valid + linestring can be generated the object is ignored. +* For relations a geometry is generated based on the `type` tag. For types + `multipolygon` and `boundary`, a multipolygon geometry is created, for types + `route` and `multilinestring` a multilinestring geometry is created, for + all other types a geometry collection is created. + +Note that for (multi)polygons it depends on the command line options \--mode +and \--full-area-limit whether the tiles calculation is based on the area or +the boundary of the (multi)polygons. + # OPTIONS This program follows the usual GNU command line syntax, with long options diff --git a/src/osm2pgsql-expire.cpp b/src/osm2pgsql-expire.cpp index d9616f869..fff07589b 100644 --- a/src/osm2pgsql-expire.cpp +++ b/src/osm2pgsql-expire.cpp @@ -189,7 +189,7 @@ void output_expire_t::relation_add(osmium::Relation const &relation) osmium::memory::Buffer tmp_buffer{1024, osmium::memory::Buffer::auto_grow::yes}; geom::geometry_t geom; - if (type == "multipolygon") { + if (type == "multipolygon" || type == "boundary") { log_debug("Creating multipolygon from relation {}...", relation.id()); geom::create_multipolygon(&geom, relation, buffer, &tmp_buffer); } else if (type == "route" || type == "multilinestring") {