diff --git a/geojson.cpp b/geojson.cpp index e1fcbbfb..a2f93db4 100644 --- a/geojson.cpp +++ b/geojson.cpp @@ -99,7 +99,7 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox return geom.size(); } -int serialize_geojson_feature(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, std::set *exclude, std::set *include, int exclude_all, int basezoom, int layer, json_object *tippecanoe, json_object *feature, std::string layername, std::map const *attribute_types) { +int serialize_geojson_feature(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, int layer, json_object *tippecanoe, json_object *feature, std::string layername, std::map const *attribute_types) { json_object *geometry_type = json_hash_get(geometry, "type"); if (geometry_type == NULL) { static int warned = 0; @@ -217,14 +217,6 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom if (properties->keys[i]->type == JSON_STRING) { std::string s(properties->keys[i]->string); - if (exclude_all) { - if (include->count(s) == 0) { - continue; - } - } else if (exclude->count(s) != 0) { - continue; - } - int type = -1; std::string val; stringify_value(properties->values[i], type, val, sst->fname, sst->line, feature, properties->keys[i]->string, attribute_types); @@ -409,8 +401,24 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { exit(EXIT_FAILURE); } + for (size_t i = 0; i < sf.full_keys.size(); i++) { + if (sst->exclude_all) { + if (sst->include->count(sf.full_keys[i]) == 0) { + sf.full_keys[i] = ""; + sf.m--; + } + } else if (sst->exclude->count(sf.full_keys[i]) != 0) { + sf.full_keys[i] = ""; + sf.m--; + } + } + if (!sst->filters) { for (size_t i = 0; i < sf.full_keys.size(); i++) { + if (sf.full_keys[i].size() == 0) { + continue; + } + type_and_string attrib; attrib.type = sf.full_values[i].type; attrib.string = sf.full_values[i].s; @@ -423,12 +431,18 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { if (inline_meta) { sf.metapos = -1; for (size_t i = 0; i < sf.full_keys.size(); i++) { + if (sf.full_keys[i].size() == 0) { + continue; + } sf.keys.push_back(addpool(r->poolfile, r->treefile, sf.full_keys[i].c_str(), mvt_string)); sf.values.push_back(addpool(r->poolfile, r->treefile, sf.full_values[i].s.c_str(), sf.full_values[i].type)); } } else { sf.metapos = r->metapos; for (size_t i = 0; i < sf.full_keys.size(); i++) { + if (sf.full_keys[i].size() == 0) { + continue; + } serialize_long_long(r->metafile, addpool(r->poolfile, r->treefile, sf.full_keys[i].c_str(), mvt_string), &r->metapos, sst->fname); serialize_long_long(r->metafile, addpool(r->poolfile, r->treefile, sf.full_values[i].s.c_str(), sf.full_values[i].type), &r->metapos, sst->fname); } @@ -487,7 +501,7 @@ void check_crs(json_object *j, const char *reading) { } } -void parse_json(struct serialization_state *sst, json_pull *jp, std::set *exclude, std::set *include, int exclude_all, int basezoom, int layer, std::string layername, std::map const *attribute_types) { +void parse_json(struct serialization_state *sst, json_pull *jp, int layer, std::string layername, std::map const *attribute_types) { long long found_hashes = 0; long long found_features = 0; long long found_geometries = 0; @@ -555,7 +569,7 @@ void parse_json(struct serialization_state *sst, json_pull *jp, std::setlength; g++) { - serialize_geojson_feature(sst, geometries->array[g], properties, id, exclude, include, exclude_all, basezoom, layer, tippecanoe, j, layername, attribute_types); + serialize_geojson_feature(sst, geometries->array[g], properties, id, layer, tippecanoe, j, layername, attribute_types); } } else { - serialize_geojson_feature(sst, geometry, properties, id, exclude, include, exclude_all, basezoom, layer, tippecanoe, j, layername, attribute_types); + serialize_geojson_feature(sst, geometry, properties, id, layer, tippecanoe, j, layername, attribute_types); } json_free(j); @@ -613,7 +627,7 @@ void parse_json(struct serialization_state *sst, json_pull *jp, std::setsst, pja->jp, pja->exclude, pja->include, pja->exclude_all, pja->basezoom, pja->layer, *pja->layername, pja->attribute_types); + parse_json(pja->sst, pja->jp, pja->layer, *pja->layername, pja->attribute_types); return NULL; } diff --git a/geojson.hpp b/geojson.hpp index ca7bf1e7..863d1996 100644 --- a/geojson.hpp +++ b/geojson.hpp @@ -11,10 +11,6 @@ struct parse_json_args { json_pull *jp; - std::set *exclude; - std::set *include; - int exclude_all; - int basezoom; int layer; std::string *layername; std::map const *attribute_types; @@ -26,7 +22,7 @@ struct parse_json_args { struct json_pull *json_begin_map(char *map, long long len); void json_end_map(struct json_pull *jp); -void parse_json(struct serialization_state *sst, json_pull *jp, std::set *exclude, std::set *include, int exclude_all, int basezoom, int layer, std::string layername, std::map const *attribute_types); +void parse_json(struct serialization_state *sst, json_pull *jp, int layer, std::string layername, std::map const *attribute_types); void *run_parse_json(void *v); #endif diff --git a/main.cpp b/main.cpp index f8a46ecf..1d825025 100644 --- a/main.cpp +++ b/main.cpp @@ -399,12 +399,12 @@ void do_read_parallel(char *map, long long len, long long initial_offset, const sst[i].uses_gamma = uses_gamma; sst[i].filters = filters; sst[i].layermap = &(*layermaps)[i]; + sst[i].exclude = exclude; + sst[i].include = include; + sst[i].exclude_all = exclude_all; + sst[i].basezoom = basezoom; pja[i].jp = json_begin_map(map + segs[i], segs[i + 1] - segs[i]); - pja[i].exclude = exclude; - pja[i].include = include; - pja[i].exclude_all = exclude_all; - pja[i].basezoom = basezoom; pja[i].layer = source; pja[i].layername = &layername; pja[i].attribute_types = attribute_types; @@ -1378,8 +1378,12 @@ int read_input(std::vector &sources, char *fname, int maxzoom, int minzo sst.filters = prefilter != NULL || postfilter != NULL; sst.uses_gamma = uses_gamma; sst.layermap = &layermaps[0]; + sst.exclude = exclude; + sst.include = include; + sst.exclude_all = exclude_all; + sst.basezoom = basezoom; - parse_json(&sst, jp, exclude, include, exclude_all, basezoom, layer, sources[layer].layer, attribute_types); + parse_json(&sst, jp, layer, sources[layer].layer, attribute_types); json_end(jp); overall_offset = layer_seq; checkdisk(reader, CPUS); diff --git a/serial.hpp b/serial.hpp index 002e7ef6..f033f188 100644 --- a/serial.hpp +++ b/serial.hpp @@ -114,10 +114,16 @@ struct serialization_state { bool want_dist; int maxzoom; + int basezoom; + bool filters; bool uses_gamma; std::map *layermap; + + std::set *exclude; + std::set *include; + int exclude_all; }; #endif