Fix writing of clipid to tile; move keys/values into feature itself

This commit is contained in:
Eric Fischer 2018-04-27 16:40:01 +02:00
parent bc303344e2
commit e2b7040339
3 changed files with 33 additions and 10 deletions

View File

@ -85,10 +85,10 @@ void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, u
state.json_write_newline();
}
std::vector<std::pair<mvt_layer, mvt_feature>> handle(std::string message, int z, unsigned x, unsigned y, std::set<std::string> const &to_decode, bool pipeline, bool stats, json_writer &state) {
std::vector<mvt_feature> handle(std::string message, int z, unsigned x, unsigned y, std::set<std::string> const &to_decode, bool pipeline, bool stats, json_writer &state) {
mvt_tile tile;
bool was_compressed;
std::vector<std::pair<mvt_layer, mvt_feature>> pending;
std::vector<mvt_feature> pending;
try {
if (!tile.decode(message, was_compressed)) {
@ -209,7 +209,8 @@ std::vector<std::pair<mvt_layer, mvt_feature>> handle(std::string message, int z
std::vector<mvt_feature> todo = layer_to_geojson(layer, z, x, y, !pipeline, pipeline, pipeline, false, 0, 0, 0, !force, state);
for (auto f : todo) {
pending.push_back(std::pair<mvt_layer, mvt_feature>(layer, f));
f.intern(layer);
pending.push_back(f);
}
if (!pipeline) {
@ -230,7 +231,7 @@ std::vector<std::pair<mvt_layer, mvt_feature>> handle(std::string message, int z
return pending;
}
void handle_split(std::vector<std::pair<mvt_layer, mvt_feature>> todo) {
void handle_split(std::vector<mvt_feature> todo) {
if (todo.size() > 0) {
printf("doing partial feature\n");
}
@ -242,7 +243,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
int oz = z;
unsigned ox = x, oy = y;
json_writer state(stdout);
std::vector<std::pair<mvt_layer, mvt_feature>> pending;
std::vector<mvt_feature> pending;
int fd = open(fname, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
@ -254,7 +255,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
if (strcmp(map, "SQLite format 3") != 0) {
if (z >= 0) {
std::string s = std::string(map, st.st_size);
std::vector<std::pair<mvt_layer, mvt_feature>> todo = handle(s, z, x, y, to_decode, pipeline, stats, state);
std::vector<mvt_feature> todo = handle(s, z, x, y, to_decode, pipeline, stats, state);
handle_split(todo);
munmap(map, st.st_size);
return;
@ -392,7 +393,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
prevz = tiles[i].z;
}
std::vector<std::pair<mvt_layer, mvt_feature>> todo = handle(s, tiles[i].z, tiles[i].x, tiles[i].y, to_decode, pipeline, stats, state);
std::vector<mvt_feature> todo = handle(s, tiles[i].z, tiles[i].x, tiles[i].y, to_decode, pipeline, stats, state);
for (auto lf : todo) {
pending.push_back(lf);
}
@ -444,7 +445,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
prevz = tz;
}
std::vector<std::pair<mvt_layer, mvt_feature>> todo = handle(std::string(s, len), tz, tx, ty, to_decode, pipeline, stats, state);
std::vector<mvt_feature> todo = handle(std::string(s, len), tz, tx, ty, to_decode, pipeline, stats, state);
for (auto lf : todo) {
pending.push_back(lf);
}
@ -489,7 +490,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
fprintf(stderr, "%s: Warning: using tile %d/%u/%u instead of %d/%u/%u\n", fname, z, x, y, oz, ox, oy);
}
std::vector<std::pair<mvt_layer, mvt_feature>> todo = handle(std::string(s, len), z, x, y, to_decode, pipeline, stats, state);
std::vector<mvt_feature> todo = handle(std::string(s, len), z, x, y, to_decode, pipeline, stats, state);
handle_split(todo);
handled = 1;

19
mvt.cpp
View File

@ -352,7 +352,7 @@ std::string mvt_tile::encode() {
}
if (layers[i].features[f].clipid != 0) {
feature_writer.add_uint64(6, layers[i].features[f].id);
feature_writer.add_uint64(6, layers[i].features[f].clipid);
}
std::vector<uint32_t> geometry;
@ -649,3 +649,20 @@ mvt_value stringified_to_mvt_value(int type, const char *s) {
return tv;
}
void mvt_feature::intern(mvt_layer &l) {
this->intern_extent = l.extent;
for (size_t i = 0; i < this->tags.size(); i++) {
mvt_value v;
if (i % 2 == 0) {
v.type = mvt_string;
v.string_value = l.keys[tags[i]];
} else {
v = l.values[tags[i]];
}
this->intern_tags.push_back(v);
}
}

View File

@ -53,10 +53,15 @@ struct mvt_feature {
bool dropped = false;
long long clipid = 0;
std::vector<mvt_value> intern_tags;
int intern_extent;
mvt_feature() {
has_id = false;
id = 0;
}
void intern(mvt_layer &l);
};
enum mvt_value_type {