Add variant that inlines float values

This commit is contained in:
Eric Fischer 2018-07-24 10:24:50 -07:00
parent b7dc84bdd7
commit 8722ec0b2f
6 changed files with 37 additions and 11 deletions

View File

@ -2652,6 +2652,8 @@ int main(int argc, char **argv) {
case 'V':
if (strcmp(optarg, "blake") == 0) {
mvt_format = mvt_blake;
} else if (strcmp(optarg, "blake_float") == 0) {
mvt_format = mvt_blake_float;
} else if (strcmp(optarg, "original") == 0) {
mvt_format = mvt_original;
} else if (strcmp(optarg, "reordered") == 0) {

21
mvt.cpp
View File

@ -592,8 +592,18 @@ void mvt_layer::tag_v3(mvt_feature &feature, std::string key, mvt_value value) {
vo = (string_values.size() << 3) | 5;
string_values.push_back(value.string_value);
} else if (value.type == mvt_float) {
if (mvt_format == mvt_blake_float) {
unsigned char buf[sizeof(float)];
memcpy(buf, &value.numeric_value.float_value, sizeof(float));
unsigned long val = 0;
for (size_t i = 0; i < sizeof(float); i++) {
val |= buf[i] << (i * 8);
}
vo = (val << 3) | 3;
} else {
vo = (float_values.size() << 3) | 3;
float_values.push_back(value.numeric_value.float_value);
}
} else if (value.type == mvt_double) {
vo = (double_values.size() << 3) | 4;
double_values.push_back(value.numeric_value.double_value);
@ -701,11 +711,22 @@ mvt_value mvt_layer::decode_property(unsigned long property) const {
case 3: /* float reference */
ret.type = mvt_float;
if (mvt_format == mvt_blake_float) {
unsigned char buf[sizeof(float)];
unsigned long val = property >> 3;
for (size_t i = 0; i < sizeof(float); i++) {
buf[i] = val >> (i * 8);
}
float f;
memcpy(&f, buf, sizeof(float));
ret.numeric_value.float_value = f;
} else {
if (property >> 3 >= float_values.size()) {
fprintf(stderr, "Out of bounds float reference: %lu vs %zu\n", property >> 3, float_values.size());
exit(EXIT_FAILURE);
}
ret.numeric_value.float_value = float_values[property >> 3];
}
return ret;
case 4: /* double reference */

View File

@ -14,6 +14,7 @@ enum mvt_fmt {
mvt_blake,
mvt_original,
mvt_reordered,
mvt_blake_float,
};
extern int mvt_format;

View File

@ -266,7 +266,7 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
if (tp >= 0 && tp != mvt_null) {
mvt_value v = stringified_to_mvt_value(tp, s.c_str());
if (mvt_format == mvt_blake) {
if (mvt_format == mvt_blake || mvt_format == mvt_blake_float) {
l->second.tag_v3(feature, std::string(properties->keys[i]->string), v);
} else {
l->second.tag(feature, std::string(properties->keys[i]->string), v);

View File

@ -317,7 +317,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
auto fa = attributes.find(k);
if (fa != attributes.end()) {
if (mvt_format == mvt_blake) {
if (mvt_format == mvt_blake || mvt_format == mvt_blake_float) {
outlayer.tag_v3(outfeature, k, fa->second.first);
} else {
outlayer.tag(outfeature, k, fa->second.first);
@ -943,6 +943,8 @@ int main(int argc, char **argv) {
case 'V':
if (strcmp(optarg, "blake") == 0) {
mvt_format = mvt_blake;
} else if (strcmp(optarg, "blake_float") == 0) {
mvt_format = mvt_blake_float;
} else if (strcmp(optarg, "original") == 0) {
mvt_format = mvt_original;
} else if (strcmp(optarg, "reordered") == 0) {

View File

@ -202,7 +202,7 @@ void decode_meta(std::vector<long long> const &metakeys, std::vector<long long>
mvt_value key = retrieve_string(metakeys[i], stringpool, NULL);
mvt_value value = retrieve_string(metavals[i], stringpool, &otype);
if (mvt_format == mvt_blake) {
if (mvt_format == mvt_blake || mvt_format == mvt_blake_float) {
layer.tag_v3(feature, key.string_value, value);
} else {
layer.tag(feature, key.string_value, value);
@ -2215,7 +2215,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
serial_val sv = layer_features[x].full_values[a];
mvt_value v = stringified_to_mvt_value(sv.type, sv.s.c_str());
if (mvt_format == mvt_blake) {
if (mvt_format == mvt_blake || mvt_format == mvt_blake_float) {
layer.tag_v3(feature, layer_features[x].full_keys[a], v);
} else {
layer.tag(feature, layer_features[x].full_keys[a], v);
@ -2235,7 +2235,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
v.type = mvt_sint;
v.numeric_value.sint_value = glow;
if (mvt_format == mvt_blake) {
if (mvt_format == mvt_blake || mvt_format == mvt_blake_float) {
layer.tag_v3(feature, "tippecanoe_feature_density", v);
} else {
layer.tag(feature, "tippecanoe_feature_density", v);