mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-23 10:30:16 +00:00
Remove dead-end idea for decoding node attributes
This commit is contained in:
parent
8980c4acba
commit
8db6f5975f
66
mvt.cpp
66
mvt.cpp
@ -441,12 +441,17 @@ bool mvt_tile::decode(std::string &message, bool &was_compressed) {
|
||||
std::vector<unsigned long> &attr = layer.features[i].node_attributes;
|
||||
size_t off = 0;
|
||||
|
||||
for (size_t j = 0; j < geom.size(); j++) {
|
||||
if (geom[j].op == mvt_moveto || geom[j].op == mvt_lineto) {
|
||||
if (off < attr.size()) {
|
||||
mvt_value v = layer.decode_property(attr, off, false);
|
||||
if (v.type == mvt_hash || v.type == mvt_list) {
|
||||
geom[j].attribute = v.string_value;
|
||||
if (attr.size() != 0) {
|
||||
for (size_t j = 0; j < geom.size(); j++) {
|
||||
if (geom[j].op == mvt_moveto || geom[j].op == mvt_lineto) {
|
||||
if (off < attr.size()) {
|
||||
mvt_value v = layer.decode_property(attr, off);
|
||||
if (v.type == mvt_hash || v.type == mvt_list) {
|
||||
geom[j].attribute = v.string_value;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Ran out of node attributes\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1043,7 +1048,7 @@ void mvt_layer::reorder_values() {
|
||||
}
|
||||
}
|
||||
|
||||
mvt_value mvt_layer::decode_property(std::vector<unsigned long> const &property, size_t &off, bool keep_list) const {
|
||||
mvt_value mvt_layer::decode_property(std::vector<unsigned long> const &property, size_t &off) const {
|
||||
int type = property[off] & 0x0F;
|
||||
mvt_value ret;
|
||||
|
||||
@ -1119,28 +1124,20 @@ mvt_value mvt_layer::decode_property(std::vector<unsigned long> const &property,
|
||||
size_t len = property[off] >> 4;
|
||||
off++;
|
||||
|
||||
if (!keep_list) {
|
||||
ret.string_value = "[";
|
||||
}
|
||||
ret.string_value = "[";
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
mvt_value v1 = decode_property(property, off, keep_list);
|
||||
mvt_value v1 = decode_property(property, off);
|
||||
off++;
|
||||
|
||||
if (keep_list) {
|
||||
ret.subvalues.push_back(v1);
|
||||
} else {
|
||||
ret.string_value.append(v1.toString());
|
||||
ret.string_value.append(v1.toString());
|
||||
|
||||
if (i + 1 < len) {
|
||||
ret.string_value.push_back(',');
|
||||
}
|
||||
if (i + 1 < len) {
|
||||
ret.string_value.push_back(',');
|
||||
}
|
||||
}
|
||||
|
||||
if (!keep_list) {
|
||||
ret.string_value.append("]");
|
||||
}
|
||||
ret.string_value.append("]");
|
||||
|
||||
off--; // so caller can increment
|
||||
return ret;
|
||||
@ -1152,34 +1149,25 @@ mvt_value mvt_layer::decode_property(std::vector<unsigned long> const &property,
|
||||
size_t len = property[off] >> 4;
|
||||
off++;
|
||||
|
||||
if (!keep_list) {
|
||||
ret.string_value = "{";
|
||||
}
|
||||
ret.string_value = "{";
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
mvt_value v1 = decode_property(property, off, keep_list);
|
||||
mvt_value v1 = decode_property(property, off);
|
||||
off++;
|
||||
|
||||
mvt_value v2 = decode_property(property, off, keep_list);
|
||||
mvt_value v2 = decode_property(property, off);
|
||||
off++;
|
||||
|
||||
if (keep_list) {
|
||||
ret.subvalues.push_back(v1);
|
||||
ret.subvalues.push_back(v2);
|
||||
} else {
|
||||
ret.string_value.append(v1.toString());
|
||||
ret.string_value.append(":");
|
||||
ret.string_value.append(v2.toString());
|
||||
ret.string_value.append(v1.toString());
|
||||
ret.string_value.append(":");
|
||||
ret.string_value.append(v2.toString());
|
||||
|
||||
if (i + 1 < len) {
|
||||
ret.string_value.push_back(',');
|
||||
}
|
||||
if (i + 1 < len) {
|
||||
ret.string_value.push_back(',');
|
||||
}
|
||||
}
|
||||
|
||||
if (!keep_list) {
|
||||
ret.string_value.append("}");
|
||||
}
|
||||
ret.string_value.append("}");
|
||||
|
||||
off--; // so caller can increment
|
||||
return ret;
|
||||
|
52
mvt.hpp
52
mvt.hpp
@ -10,7 +10,6 @@
|
||||
|
||||
struct mvt_value;
|
||||
struct mvt_layer;
|
||||
struct mvt_geometry;
|
||||
|
||||
enum mvt_fmt {
|
||||
mvt_blake,
|
||||
@ -26,6 +25,30 @@ enum mvt_operation {
|
||||
mvt_closepath = 7
|
||||
};
|
||||
|
||||
struct mvt_geometry {
|
||||
long long x = 0;
|
||||
long long y = 0;
|
||||
int /* mvt_operation */ op = 0;
|
||||
std::vector<double> elevations;
|
||||
std::vector<unsigned long> attributes;
|
||||
std::string attribute;
|
||||
|
||||
mvt_geometry(int op, long long x, long long y);
|
||||
mvt_geometry(int op, long long x, long long y, std::vector<double> elevation);
|
||||
|
||||
bool operator<(mvt_geometry const &s) const {
|
||||
if (y < s.y || (y == s.y && x < s.x)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(mvt_geometry const &s) const {
|
||||
return y == s.y && x == s.x;
|
||||
}
|
||||
};
|
||||
|
||||
enum mvt_geometry_type {
|
||||
mvt_point = 1,
|
||||
mvt_linestring = 2,
|
||||
@ -76,7 +99,6 @@ struct mvt_value {
|
||||
bool bool_value;
|
||||
int null_value;
|
||||
} numeric_value;
|
||||
std::vector<mvt_value> subvalues;
|
||||
|
||||
bool operator<(const mvt_value &o) const;
|
||||
std::string toString() const;
|
||||
@ -88,30 +110,6 @@ struct mvt_value {
|
||||
}
|
||||
};
|
||||
|
||||
struct mvt_geometry {
|
||||
long long x = 0;
|
||||
long long y = 0;
|
||||
int /* mvt_operation */ op = 0;
|
||||
std::vector<double> elevations;
|
||||
std::vector<unsigned long> attributes;
|
||||
std::string attribute;
|
||||
|
||||
mvt_geometry(int op, long long x, long long y);
|
||||
mvt_geometry(int op, long long x, long long y, std::vector<double> elevation);
|
||||
|
||||
bool operator<(mvt_geometry const &s) const {
|
||||
if (y < s.y || (y == s.y && x < s.x)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(mvt_geometry const &s) const {
|
||||
return y == s.y && x == s.x;
|
||||
}
|
||||
};
|
||||
|
||||
struct mvt_attribute_pool {
|
||||
std::vector<std::string> keys{};
|
||||
std::vector<std::string> string_values{};
|
||||
@ -143,7 +141,7 @@ struct mvt_layer {
|
||||
std::map<mvt_value, size_t> value_map{};
|
||||
std::map<mvt_value, unsigned long> property_map{};
|
||||
|
||||
mvt_value decode_property(std::vector<unsigned long> const &property, size_t &off, bool keep_list) const;
|
||||
mvt_value decode_property(std::vector<unsigned long> const &property, size_t &off) const;
|
||||
void reorder_values();
|
||||
};
|
||||
|
||||
|
@ -170,7 +170,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
||||
}
|
||||
std::string key = layer.attribute_pool.keys[feat.properties[t]];
|
||||
t++;
|
||||
mvt_value val = layer.decode_property(feat.properties, t, false);
|
||||
mvt_value val = layer.decode_property(feat.properties, t);
|
||||
|
||||
attributes.insert(std::pair<std::string, mvt_value>(key, val));
|
||||
}
|
||||
@ -236,7 +236,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
||||
|
||||
std::string key = layer.attribute_pool.keys[feat.properties[t]];
|
||||
t++;
|
||||
mvt_value val = layer.decode_property(feat.properties, t, false);
|
||||
mvt_value val = layer.decode_property(feat.properties, t);
|
||||
|
||||
todo.push_back(std::pair<std::string, mvt_value>(key, val));
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y
|
||||
const char *key = layer.attribute_pool.keys[feat.properties[t]].c_str();
|
||||
|
||||
t++;
|
||||
mvt_value const &val = layer.decode_property(feat.properties, t, false);
|
||||
mvt_value const &val = layer.decode_property(feat.properties, t);
|
||||
|
||||
state.json_write_string(key);
|
||||
print_val(feat, layer, val, 0, state);
|
||||
|
Loading…
x
Reference in New Issue
Block a user