From 52c30cd2dc5e1fdbe5a44b13295179e3a5a8dd01 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Mon, 22 Jan 2024 16:06:21 -0800 Subject: [PATCH] Plumbing the accumulate-attribute option around --- Makefile | 2 +- clip.cpp | 11 ++++++----- geometry.hpp | 7 +++++-- overzoom.cpp | 9 ++++++++- tile-join.cpp | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 3e21845a..a14e7fd4 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o unit: unit.o text.o sort.o mvt.o $(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread -tippecanoe-overzoom: overzoom.o mvt.o clip.o evaluator.o jsonpull/jsonpull.o text.o +tippecanoe-overzoom: overzoom.o mvt.o clip.o evaluator.o jsonpull/jsonpull.o text.o attribute.o $(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread -include $(wildcard *.d) diff --git a/clip.cpp b/clip.cpp index 1c2b34fe..26ea66c0 100644 --- a/clip.cpp +++ b/clip.cpp @@ -9,6 +9,7 @@ #include "mvt.hpp" #include "evaluator.hpp" #include "serial.hpp" +#include "attribute.hpp" static std::vector> clip_poly1(std::vector> &geom, long long minx, long long miny, long long maxx, long long maxy, @@ -757,7 +758,7 @@ static std::vector> clip_poly1(std::vector const &keep, bool do_compress, std::vector> *next_overzoomed_tiles, - bool demultiply, json_object *filter, bool preserve_input_order) { + bool demultiply, json_object *filter, bool preserve_input_order, std::map const &attribute_accum) { mvt_tile tile; try { @@ -771,7 +772,7 @@ std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int exit(EXIT_PROTOBUF); } - return overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order); + return overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum); } struct tile_feature { @@ -784,7 +785,7 @@ struct tile_feature { size_t seq = 0; }; -void feature_out(tile_feature const &feature, mvt_layer &outlayer, std::set const &keep) { +static void feature_out(tile_feature const &feature, mvt_layer &outlayer, std::set const &keep) { // Add geometry to output feature mvt_feature outfeature; @@ -822,7 +823,7 @@ static struct preservecmp { std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny, int detail, int buffer, std::set const &keep, bool do_compress, std::vector> *next_overzoomed_tiles, - bool demultiply, json_object *filter, bool preserve_input_order) { + bool demultiply, json_object *filter, bool preserve_input_order, std::map const &attribute_accum) { mvt_tile outtile; for (auto const &layer : tile.layers) { @@ -985,7 +986,7 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int std::string child = overzoom(outtile, nz, nx, ny, nz + 1, nx * 2 + x, ny * 2 + y, detail, buffer, keep, false, NULL, - demultiply, filter, preserve_input_order); + demultiply, filter, preserve_input_order, attribute_accum); if (child.size() > 0) { next_overzoomed_tiles->emplace_back(nx * 2 + x, ny * 2 + y); } diff --git a/geometry.hpp b/geometry.hpp index ed4b6bd9..c4fa4d85 100644 --- a/geometry.hpp +++ b/geometry.hpp @@ -9,6 +9,7 @@ #include #include #include "jsonpull/jsonpull.h" +#include "attribute.hpp" #define VT_POINT 1 #define VT_LINE 2 @@ -102,11 +103,13 @@ double distance_from_line(long long point_x, long long point_y, long long segA_x std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny, int detail, int buffer, std::set const &keep, bool do_compress, std::vector> *next_overzoomed_tiles, - bool demultiply, json_object *filter, bool preserve_input_order); + bool demultiply, json_object *filter, bool preserve_input_order, + std::map const &attribute_accum); std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny, int detail, int buffer, std::set const &keep, bool do_compress, std::vector> *next_overzoomed_tiles, - bool demultiply, json_object *filter, bool preserve_input_order); + bool demultiply, json_object *filter, bool preserve_input_order, + std::map const &attribute_accum); #endif diff --git a/overzoom.cpp b/overzoom.cpp index e2944a1f..1c9d365e 100644 --- a/overzoom.cpp +++ b/overzoom.cpp @@ -7,6 +7,7 @@ #include "mvt.hpp" #include "geometry.hpp" #include "evaluator.hpp" +#include "attribute.hpp" extern char *optarg; extern int optind; @@ -16,6 +17,7 @@ int buffer = 5; // tippecanoe-style: mvt buffer == extent * buffer / 256; bool demultiply = false; std::string filter; bool preserve_input_order = false; +std::map attribute_accum; std::set keep; @@ -37,6 +39,7 @@ int main(int argc, char **argv) { {"filter-points-multiplier", no_argument, 0, 'm'}, {"feature-filter", required_argument, 0, 'j'}, {"preserve-input-order", no_argument, 0, 'o' & 0x1F}, + {"accumulate-attribute", required_argument, 0, 'E'}, {0, 0, 0, 0}, }; @@ -83,6 +86,10 @@ int main(int argc, char **argv) { preserve_input_order = true; break; + case 'E': + set_attribute_accum(attribute_accum, optarg, argv); + break; + default: fprintf(stderr, "Unrecognized flag -%c\n", i); usage(argv); @@ -137,7 +144,7 @@ int main(int argc, char **argv) { json_filter = parse_filter(filter.c_str()); } - std::string out = overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, true, NULL, demultiply, json_filter, preserve_input_order); + std::string out = overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, true, NULL, demultiply, json_filter, preserve_input_order, attribute_accum); fwrite(out.c_str(), sizeof(char), out.size(), f); fclose(f); diff --git a/tile-join.cpp b/tile-join.cpp index 02cb6089..e83fa47a 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -703,7 +703,7 @@ struct tileset_reader { } if (source.layers.size() != 0) { - std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, -1, buffer, std::set(), false, &next_overzoomed_tiles, false, NULL, false); + std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, -1, buffer, std::set(), false, &next_overzoomed_tiles, false, NULL, false, std::map()); return ret; }