Unify some duplicated code, but it still loses the node attributes

This commit is contained in:
Eric Fischer 2018-08-30 17:19:34 -07:00
parent 86cf0a5598
commit b7e56dd4a0
4 changed files with 27 additions and 36 deletions

24
mvt.cpp
View File

@ -1316,3 +1316,27 @@ mvt_value stringified_to_mvt_value(int type, const char *s) {
return tv;
}
std::vector<mvt_geometry> to_feature(drawvec &geom, mvt_layer &layer) {
std::vector<mvt_geometry> out;
for (size_t i = 0; i < geom.size(); i++) {
mvt_geometry g(geom[i].op, geom[i].x, geom[i].y, geom[i].elevations);
if (geom[i].attributes.size() != 0) {
json_pull *jp = json_begin_string(geom[i].attributes.c_str());
json_object *jo = json_read_tree(jp);
if (jo == NULL) {
fprintf(stderr, "Internal error: failed to reconstruct JSON %s\n", geom[i].attributes.c_str());
exit(EXIT_FAILURE);
}
tag_object_v3(layer, jo, g.attributes);
json_free(jo);
json_end(jp);
}
out.push_back(g);
}
return out;
}

View File

@ -7,6 +7,7 @@
#include <set>
#include <vector>
#include <jsonpull/jsonpull.h>
#include "geometry.hpp"
struct mvt_value;
struct mvt_layer;
@ -162,4 +163,5 @@ mvt_value stringified_to_mvt_value(int type, const char *s);
bool is_integer(const char *s, long long *v);
bool is_unsigned_integer(const char *s, unsigned long long *v);
std::vector<mvt_geometry> to_feature(drawvec &geom, mvt_layer &layer);
#endif

View File

@ -72,17 +72,6 @@ void *run_writer(void *a) {
return NULL;
}
// XXX deduplicate
static std::vector<mvt_geometry> to_feature(drawvec &geom) {
std::vector<mvt_geometry> out;
for (size_t i = 0; i < geom.size(); i++) {
out.push_back(mvt_geometry(geom[i].op, geom[i].x, geom[i].y, geom[i].elevations));
}
return out;
}
// Reads from the postfilter
std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::vector<std::map<std::string, layermap_entry>> *layermaps, size_t tiling_seg, std::vector<std::vector<std::string>> *layer_unmaps, int extent) {
std::map<std::string, mvt_layer> ret;
@ -221,7 +210,7 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
if (dv.size() > 0) {
mvt_feature feature;
feature.type = mb_geometry[t];
feature.geometry = to_feature(dv);
feature.geometry = to_feature(dv, l->second);
json_object *id = json_hash_get(j, "id");
if (id != NULL) {

View File

@ -58,30 +58,6 @@ extern "C" {
pthread_mutex_t db_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t var_lock = PTHREAD_MUTEX_INITIALIZER;
std::vector<mvt_geometry> to_feature(drawvec &geom, mvt_layer &layer) {
std::vector<mvt_geometry> out;
for (size_t i = 0; i < geom.size(); i++) {
mvt_geometry g(geom[i].op, geom[i].x, geom[i].y, geom[i].elevations);
if (geom[i].attributes.size() != 0) {
json_pull *jp = json_begin_string(geom[i].attributes.c_str());
json_object *jo = json_read_tree(jp);
if (jo == NULL) {
fprintf(stderr, "Internal error: failed to reconstruct JSON %s\n", geom[i].attributes.c_str());
exit(EXIT_FAILURE);
}
tag_object_v3(layer, jo, g.attributes);
json_free(jo);
json_end(jp);
}
out.push_back(g);
}
return out;
}
bool draws_something(drawvec &geom) {
for (size_t i = 1; i < geom.size(); i++) {
if (geom[i].op == VT_LINETO && (geom[i].x != geom[i - 1].x || geom[i].y != geom[i - 1].y)) {