Make sure features with the same clipid also have matching attributes

This commit is contained in:
Eric Fischer 2018-04-27 17:33:31 +02:00
parent e2b7040339
commit c1590ef6a1
4 changed files with 51 additions and 10 deletions

View File

@ -231,10 +231,31 @@ std::vector<mvt_feature> handle(std::string message, int z, unsigned x, unsigned
return pending; 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<mvt_feature> todo) { void handle_split(std::vector<mvt_feature> todo) {
if (todo.size() > 0) { if (todo.size() > 0) {
printf("doing partial feature\n"); 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<std::string> const &to_decode, bool pipeline, bool stats) { void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> const &to_decode, bool pipeline, bool stats) {

18
mvt.cpp
View File

@ -447,6 +447,24 @@ bool mvt_value::operator<(const mvt_value &o) const {
return false; 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) { static std::string quote(std::string const &s) {
std::string buf; std::string buf;

View File

@ -95,6 +95,8 @@ struct mvt_value {
this->string_value = ""; this->string_value = "";
this->numeric_value.double_value = 0; this->numeric_value.double_value = 0;
} }
bool operator==(const mvt_value &o) const;
}; };
struct mvt_layer { struct mvt_layer {

View File

@ -227,18 +227,18 @@ void json_writer::adds(std::string const &str) {
} }
static void aprintf(std::string *buf, const char *format, ...) { static void aprintf(std::string *buf, const char *format, ...) {
va_list ap; va_list ap;
char *tmp; char *tmp;
va_start(ap, format); va_start(ap, format);
if (vasprintf(&tmp, format, ap) < 0) { if (vasprintf(&tmp, format, ap) < 0) {
fprintf(stderr, "memory allocation failure\n"); fprintf(stderr, "memory allocation failure\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
va_end(ap); va_end(ap);
buf->append(tmp, strlen(tmp)); buf->append(tmp, strlen(tmp));
free(tmp); free(tmp);
} }
struct lonlat { struct lonlat {