Allow filter expressions during tippecanoe as well as during tile-join

This commit is contained in:
Eric Fischer
2017-09-01 11:51:12 -07:00
parent dbb789dadc
commit 0fd4454129
9 changed files with 131 additions and 53 deletions
+50 -6
View File
@@ -256,11 +256,55 @@ bool eval(std::map<std::string, mvt_value> const &feature, json_object *f) {
}
bool evaluate(std::map<std::string, mvt_value> const &feature, std::string const &layer, json_object *filter) {
json_object *f = json_hash_get(filter, layer.c_str());
if (f != NULL) {
return eval(feature, f);
} else {
return true; // no filter for this layer;
if (filter == NULL || filter->type != JSON_HASH) {
fprintf(stderr, "Error: filter is not a hash: %s\n", json_stringify(filter));
exit(EXIT_FAILURE);
}
bool ok = true;
json_object *f;
f = json_hash_get(filter, layer.c_str());
if (ok && f != NULL) {
ok = eval(feature, f);
}
f = json_hash_get(filter, "*");
if (ok && f != NULL) {
ok = eval(feature, f);
}
return ok;
}
json_object *read_filter(const char *fname) {
FILE *fp = fopen(fname, "r");
if (fp == NULL) {
perror(fname);
exit(EXIT_FAILURE);
}
json_pull *jp = json_begin_file(fp);
json_object *filter = json_read_tree(jp);
if (filter == NULL) {
fprintf(stderr, "%s: %s\n", fname, jp->error);
exit(EXIT_FAILURE);
}
json_disconnect(filter);
json_end(jp);
fclose(fp);
return filter;
}
json_object *parse_filter(const char *s) {
json_pull *jp = json_begin_string(s);
json_object *filter = json_read_tree(jp);
if (filter == NULL) {
fprintf(stderr, "Could not parse filter %s\n", s);
fprintf(stderr, "%s\n", jp->error);
exit(EXIT_FAILURE);
}
json_disconnect(filter);
json_end(jp);
return filter;
}