From c1590ef6a1296da6723ab3c8287ab80f1217e8f1 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 27 Apr 2018 17:33:31 +0200 Subject: [PATCH] Make sure features with the same clipid also have matching attributes --- decode.cpp | 21 +++++++++++++++++++++ mvt.cpp | 18 ++++++++++++++++++ mvt.hpp | 2 ++ write_json.cpp | 20 ++++++++++---------- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/decode.cpp b/decode.cpp index e02cf1c..ecc786f 100644 --- a/decode.cpp +++ b/decode.cpp @@ -231,10 +231,31 @@ std::vector handle(std::string message, int z, unsigned x, unsigned return pending; } +struct by_clipid { + bool operator()(const mvt_feature &a, const mvt_feature &b) { + return a.clipid < b.clipid; + } +}; + void handle_split(std::vector todo) { if (todo.size() > 0) { printf("doing partial feature\n"); } + + std::sort(todo.begin(), todo.end(), by_clipid()); + + for (size_t i = 1; i < todo.size(); i++) { + if (todo[i - 1].clipid > todo[i].clipid) { + fprintf(stderr, "Internal error: failed to sort by clipid\n"); + exit(EXIT_FAILURE); + } + if (todo[i - 1].clipid == todo[i].clipid) { + if (todo[i - 1].intern_tags != todo[i].intern_tags) { + fprintf(stderr, "Feature clipids match but attributes don't\n"); + exit(EXIT_FAILURE); + } + } + } } void decode(char *fname, int z, unsigned x, unsigned y, std::set const &to_decode, bool pipeline, bool stats) { diff --git a/mvt.cpp b/mvt.cpp index 9a18672..e9be35f 100644 --- a/mvt.cpp +++ b/mvt.cpp @@ -447,6 +447,24 @@ bool mvt_value::operator<(const mvt_value &o) const { return false; } +bool mvt_value::operator==(const mvt_value &o) const { + if (type != o.type) { + return false; + } + + if ((type == mvt_string && string_value == o.string_value) || + (type == mvt_float && numeric_value.float_value == o.numeric_value.float_value) || + (type == mvt_double && numeric_value.double_value == o.numeric_value.double_value) || + (type == mvt_int && numeric_value.int_value == o.numeric_value.int_value) || + (type == mvt_uint && numeric_value.uint_value == o.numeric_value.uint_value) || + (type == mvt_sint && numeric_value.sint_value == o.numeric_value.sint_value) || + (type == mvt_bool && numeric_value.bool_value == o.numeric_value.bool_value)) { + return true; + } + + return false; +} + static std::string quote(std::string const &s) { std::string buf; diff --git a/mvt.hpp b/mvt.hpp index b6ad9cb..be8b91e 100644 --- a/mvt.hpp +++ b/mvt.hpp @@ -95,6 +95,8 @@ struct mvt_value { this->string_value = ""; this->numeric_value.double_value = 0; } + + bool operator==(const mvt_value &o) const; }; struct mvt_layer { diff --git a/write_json.cpp b/write_json.cpp index 42bf930..ac83309 100644 --- a/write_json.cpp +++ b/write_json.cpp @@ -227,18 +227,18 @@ void json_writer::adds(std::string const &str) { } static void aprintf(std::string *buf, const char *format, ...) { - va_list ap; - char *tmp; + va_list ap; + char *tmp; - va_start(ap, format); - if (vasprintf(&tmp, format, ap) < 0) { - fprintf(stderr, "memory allocation failure\n"); - exit(EXIT_FAILURE); - } - va_end(ap); + va_start(ap, format); + if (vasprintf(&tmp, format, ap) < 0) { + fprintf(stderr, "memory allocation failure\n"); + exit(EXIT_FAILURE); + } + va_end(ap); - buf->append(tmp, strlen(tmp)); - free(tmp); + buf->append(tmp, strlen(tmp)); + free(tmp); } struct lonlat {