Should keep pre/postfilter from losing node attributes, but not working

This commit is contained in:
Eric Fischer 2018-08-30 16:39:39 -07:00
parent 09f76cdf2a
commit 86cf0a5598
4 changed files with 36 additions and 16 deletions

View File

@ -185,20 +185,7 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
if (attributes != NULL) {
drawvec dv2;
parse_geometry(t, attributes, dv2, VT_MOVETO, sst->fname, sst->line, feature, true);
if (dv2.size() != dv.size()) {
fprintf(stderr, "Geometry attributes don't match coordinates\n");
exit(EXIT_FAILURE);
}
for (size_t i = 0; i < dv2.size(); i++) {
if (dv[i].op != dv2[i].op) {
fprintf(stderr, "Geometry attributes don't match coordinates\n");
exit(EXIT_FAILURE);
}
dv[i].attributes = dv2[i].attributes;
}
merge_node_attributes(dv, dv2);
}
serial_feature sf;

View File

@ -152,6 +152,10 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
json_context(j);
exit(EXIT_FAILURE);
}
json_object *attributes = json_hash_get(geometry, "attributes");
if (attributes == NULL || attributes ->type != JSON_ARRAY) {
attributes = NULL;
}
int t;
for (t = 0; t < GEOM_TYPES; t++) {
@ -187,7 +191,11 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
drawvec dv;
parse_geometry(t, coordinates, dv, VT_MOVETO, "Filter output", jp->line, j, false);
// XXX do node attributes
if (attributes != NULL) {
drawvec dv2;
parse_geometry(t, attributes, dv, VT_MOVETO, "Filter output", jp->line, j, true);
merge_node_attributes(dv, dv2);
}
if (mb_geometry[t] == VT_POLYGON) {
dv = fix_polygon(dv);
}
@ -363,6 +371,10 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
json_context(j);
exit(EXIT_FAILURE);
}
json_object *attributes = json_hash_get(geometry, "attributes");
if (attributes == NULL || attributes->type != JSON_ARRAY) {
attributes = NULL;
}
int t;
for (t = 0; t < GEOM_TYPES; t++) {
@ -378,7 +390,11 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
drawvec dv;
parse_geometry(t, coordinates, dv, VT_MOVETO, "Filter output", jp->line, j, false);
// XXX do node attributes
if (attributes != NULL) {
drawvec dv2;
parse_geometry(t, attributes, dv, VT_MOVETO, "Filter output", jp->line, j, true);
merge_node_attributes(dv, dv2);
}
if (mb_geometry[t] == VT_POLYGON) {
dv = fix_polygon(dv);
}

View File

@ -130,6 +130,22 @@ void parse_geometry(int t, json_object *j, drawvec &out, int op, const char *fna
}
}
void merge_node_attributes(drawvec &geom, drawvec &attributes) {
if (attributes.size() != geom.size()) {
fprintf(stderr, "Geometry attributes don't match coordinates\n");
exit(EXIT_FAILURE);
}
for (size_t i = 0; i < attributes.size(); i++) {
if (geom[i].op != attributes[i].op) {
fprintf(stderr, "Geometry attributes don't match coordinates\n");
exit(EXIT_FAILURE);
}
geom[i].attributes = attributes[i].attributes;
}
}
void canonicalize(json_object *o) {
if (o->type == JSON_NUMBER) {
std::string s;

View File

@ -12,5 +12,6 @@ extern int mb_geometry[GEOM_TYPES];
void json_context(json_object *j);
void parse_geometry(int t, json_object *j, drawvec &out, int op, const char *fname, int line, json_object *feature, bool doing_attributes);
void merge_node_attributes(drawvec &geom, drawvec &attributes);
void stringify_value(json_object *value, int &type, std::string &stringified, const char *reading, int line, json_object *feature);