From 9942b8db55a8b903ba3321f0a3868ea759d79f84 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Fri, 16 Feb 2024 10:06:01 -0800 Subject: [PATCH] Add multiplier stripping from tippecanoe-overzoom to tile-join --- README.md | 3 +++ man/tippecanoe.1 | 6 ++++++ tile-join.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 6d49ffff..e20f1405 100644 --- a/README.md +++ b/README.md @@ -810,6 +810,9 @@ The options are: * `-j` *filter* or `--feature-filter`=*filter*: Check features against a per-layer filter (as defined in the [Mapbox GL Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/#other-filter)) and only include those that match. Any features in layers that have no filter specified will be passed through. Filters for the layer `"*"` apply to all layers. * `-J` *filter-file* or `--feature-filter-file`=*filter-file*: Like `-j`, but read the filter from a file. * `-pe` or `--empty-csv-columns-are-null`: Treat empty CSV columns as nulls rather than as empty strings. + * `-m`: If a tile was created with the `--retain-points-multiplier` option, thin the tile back down to its normal feature count during overzooming. The first feature from each cluster will be retained, unless `-j` is used to specify a filter, in which case the first matching filter from each cluster will be retained instead. + * `--preserve-input-order`: Restore a set of filtered features to its original input order + * `--accumulate-attribute`: Behaves as in `tippecanoe` to sum attributes from the features of a multiplier cluster that are not included in the final output. The attributes from features that are filtered away with `-j` are *not* accumulated onto the output feature. ### Setting or disabling tile size limits diff --git a/man/tippecanoe.1 b/man/tippecanoe.1 index 13995fd0..2d8d0c7c 100644 --- a/man/tippecanoe.1 +++ b/man/tippecanoe.1 @@ -1033,6 +1033,12 @@ The options are: \fB\fC\-J\fR \fIfilter\-file\fP or \fB\fC\-\-feature\-filter\-file\fR=\fIfilter\-file\fP: Like \fB\fC\-j\fR, but read the filter from a file. .IP \(bu 2 \fB\fC\-pe\fR or \fB\fC\-\-empty\-csv\-columns\-are\-null\fR: Treat empty CSV columns as nulls rather than as empty strings. +.IP \(bu 2 +\fB\fC\-m\fR: If a tile was created with the \fB\fC\-\-retain\-points\-multiplier\fR option, thin the tile back down to its normal feature count during overzooming. The first feature from each cluster will be retained, unless \fB\fC\-j\fR is used to specify a filter, in which case the first matching filter from each cluster will be retained instead. +.IP \(bu 2 +\fB\fC\-\-preserve\-input\-order\fR: Restore a set of filtered features to its original input order +.IP \(bu 2 +\fB\fC\-\-accumulate\-attribute\fR: Behaves as in \fB\fCtippecanoe\fR to sum attributes from the features of a multiplier cluster that are not included in the final output. The attributes from features that are filtered away with \fB\fC\-j\fR are \fInot\fP accumulated onto the output feature. .RE .SS Setting or disabling tile size limits .RS diff --git a/tile-join.cpp b/tile-join.cpp index c3e2b3fe..879c8862 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -55,6 +55,9 @@ int minzoom = 0; std::map renames; bool exclude_all = false; std::vector unidecode_data; +bool preserve_input_order = false; +bool demultiply = false; +std::unordered_map attribute_accum; bool want_overzoom = false; int buffer = 5; @@ -73,6 +76,12 @@ struct stats { }; void append_tile(std::string message, int z, unsigned x, unsigned y, std::map &layermap, std::vector &header, std::map> &mapping, std::set &exclude, std::set &include, std::set &keep_layers, std::set &remove_layers, int ifmatched, mvt_tile &outtile, json_object *filter) { + if (attribute_accum.size() > 0 || demultiply) { + message = overzoom(message, z, x, y, z, x, y, + -1 /* detail */, 128 /* buffer */, include, false /* compress */, NULL /* child tiles */, + demultiply, filter, preserve_input_order, attribute_accum, unidecode_data); + } + mvt_tile tile; int features_added = 0; bool was_compressed; @@ -735,6 +744,7 @@ struct arg { std::set *remove_layers = NULL; int ifmatched = 0; json_object *filter = NULL; + struct tileset_reader *readers = NULL; }; @@ -1235,6 +1245,9 @@ int main(int argc, char **argv) { {"tile-stats-attributes-limit", required_argument, 0, '~'}, {"tile-stats-sample-values-limit", required_argument, 0, '~'}, {"tile-stats-values-limit", required_argument, 0, '~'}, + {"filter-points-multiplier", no_argument, 0, 'm'}, + {"preserve-input-order", no_argument, 0, 'o' & 0x1F}, + {"accumulate-attribute", required_argument, 0, 'E'}, {"unidecode-data", required_argument, 0, '~'}, {0, 0, 0, 0}, @@ -1402,6 +1415,18 @@ int main(int argc, char **argv) { quiet = true; break; + case 'm': + demultiply = true; + break; + + case 'o' & 0x1F: + preserve_input_order = true; + break; + + case 'E': + set_attribute_accum(attribute_accum, optarg, argv); + break; + case '~': { const char *opt = long_options[option_index].name; if (strcmp(opt, "tile-stats-attributes-limit") == 0) {