mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Add --accumulate-attribute to tippecanoe-overzoom (#189)
* Starting to factor out attribute accumulation into its own file * Continuing to factor out attribute accumulation * Reduce duplicate code * Plumbing the accumulate-attribute option around * Call the attribute accumulator * Test that accumulation works * Add missing #includes * Don't sort within individual multiplier clusters Doing so throws off the spatial distribution of the low zooms * Docs and changelog * Add comments
This commit is contained in:
+8
-53
@@ -70,21 +70,6 @@ struct stats {
|
||||
std::vector<struct strategy> strategies;
|
||||
};
|
||||
|
||||
void aprintf(std::string *buf, const char *format, ...) {
|
||||
va_list ap;
|
||||
char *tmp;
|
||||
|
||||
va_start(ap, format);
|
||||
if (vasprintf(&tmp, format, ap) < 0) {
|
||||
fprintf(stderr, "memory allocation failure\n");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
buf->append(tmp, strlen(tmp));
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<std::string, layermap_entry> &layermap, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping, std::set<std::string> &exclude, std::set<std::string> &include, std::set<std::string> &keep_layers, std::set<std::string> &remove_layers, int ifmatched, mvt_tile &outtile, json_object *filter) {
|
||||
mvt_tile tile;
|
||||
int features_added = 0;
|
||||
@@ -173,49 +158,19 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
|
||||
for (size_t t = 0; t + 1 < feat.tags.size(); t += 2) {
|
||||
const char *key = layer.keys[feat.tags[t]].c_str();
|
||||
mvt_value &val = layer.values[feat.tags[t + 1]];
|
||||
std::string value;
|
||||
int type = -1;
|
||||
serial_val sv = mvt_value_to_serial_val(val);
|
||||
|
||||
if (val.type == mvt_string) {
|
||||
value = val.string_value;
|
||||
type = mvt_string;
|
||||
} else if (val.type == mvt_int) {
|
||||
aprintf(&value, "%lld", (long long) val.numeric_value.int_value);
|
||||
type = mvt_double;
|
||||
} else if (val.type == mvt_double) {
|
||||
aprintf(&value, "%s", milo::dtoa_milo(val.numeric_value.double_value).c_str());
|
||||
type = mvt_double;
|
||||
} else if (val.type == mvt_float) {
|
||||
aprintf(&value, "%s", milo::dtoa_milo(val.numeric_value.float_value).c_str());
|
||||
type = mvt_double;
|
||||
} else if (val.type == mvt_bool) {
|
||||
aprintf(&value, "%s", val.numeric_value.bool_value ? "true" : "false");
|
||||
type = mvt_bool;
|
||||
} else if (val.type == mvt_sint) {
|
||||
aprintf(&value, "%lld", (long long) val.numeric_value.sint_value);
|
||||
type = mvt_double;
|
||||
} else if (val.type == mvt_uint) {
|
||||
aprintf(&value, "%llu", (long long) val.numeric_value.uint_value);
|
||||
type = mvt_double;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type < 0) {
|
||||
if (sv.type == mvt_null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (include.count(std::string(key)) || (!exclude_all && exclude.count(std::string(key)) == 0 && exclude_attributes.count(std::string(key)) == 0)) {
|
||||
serial_val sv;
|
||||
sv.type = type;
|
||||
sv.s = value;
|
||||
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, serial_val>>(key, std::pair<mvt_value, serial_val>(val, sv)));
|
||||
key_order.push_back(key);
|
||||
}
|
||||
|
||||
if (header.size() > 0 && strcmp(key, header[0].c_str()) == 0) {
|
||||
std::map<std::string, std::vector<std::string>>::iterator ii = mapping.find(value);
|
||||
std::map<std::string, std::vector<std::string>>::iterator ii = mapping.find(sv.s);
|
||||
|
||||
if (ii != mapping.end()) {
|
||||
std::vector<std::string> fields = ii->second;
|
||||
@@ -253,14 +208,14 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
|
||||
attributes.erase(fa);
|
||||
}
|
||||
|
||||
serial_val sv;
|
||||
sv.type = outval.type;
|
||||
sv.s = joinval;
|
||||
serial_val outsv;
|
||||
outsv.type = outval.type;
|
||||
outsv.s = joinval;
|
||||
|
||||
// Convert from double to int if the joined attribute is an integer
|
||||
outval = stringified_to_mvt_value(outval.type, joinval.c_str());
|
||||
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, serial_val>>(joinkey, std::pair<mvt_value, serial_val>(outval, sv)));
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, serial_val>>(joinkey, std::pair<mvt_value, serial_val>(outval, outsv)));
|
||||
key_order.push_back(joinkey);
|
||||
}
|
||||
}
|
||||
@@ -744,7 +699,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<std::string>(), 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<std::string>(), false, &next_overzoomed_tiles, false, NULL, false, std::map<std::string, attribute_op>());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user