Split more serialization details out from being parsing parameters

This commit is contained in:
Eric Fischer 2017-08-24 15:46:35 -07:00
parent b114e22d39
commit ed8fbd0236
4 changed files with 30 additions and 26 deletions

View File

@ -38,7 +38,7 @@
#include "read_json.hpp" #include "read_json.hpp"
#include "mvt.hpp" #include "mvt.hpp"
int serialize_feature(struct serialization_state *sst, serial_feature &sf, bool want_dist, bool filters, int maxzoom, bool uses_gamma); int serialize_feature(struct serialization_state *sst, serial_feature &sf);
static long long scale_geometry(struct serialization_state *sst, long long *bbox, drawvec &geom) { static long long scale_geometry(struct serialization_state *sst, long long *bbox, drawvec &geom) {
long long offset = 0; long long offset = 0;
@ -99,7 +99,7 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox
return geom.size(); return geom.size();
} }
int serialize_geometry(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int layer, double droprate, json_object *tippecanoe, int maxzoom, json_object *feature, std::map<std::string, layermap_entry> *layermap, std::string layername, bool uses_gamma, std::map<std::string, int> const *attribute_types, bool want_dist, bool filters) { int serialize_geojson_feature(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int layer, json_object *tippecanoe, json_object *feature, std::map<std::string, layermap_entry> *layermap, std::string layername, std::map<std::string, int> const *attribute_types) {
json_object *geometry_type = json_hash_get(geometry, "type"); json_object *geometry_type = json_hash_get(geometry, "type");
if (geometry_type == NULL) { if (geometry_type == NULL) {
static int warned = 0; static int warned = 0;
@ -202,7 +202,7 @@ int serialize_geometry(struct serialization_state *sst, json_object *geometry, j
} }
} }
if (!filters) { if (!sst->filters) {
if (tippecanoe_layername.size() != 0) { if (tippecanoe_layername.size() != 0) {
if (layermap->count(tippecanoe_layername) == 0) { if (layermap->count(tippecanoe_layername) == 0) {
layermap->insert(std::pair<std::string, layermap_entry>(tippecanoe_layername, layermap_entry(layermap->size()))); layermap->insert(std::pair<std::string, layermap_entry>(tippecanoe_layername, layermap_entry(layermap->size())));
@ -275,7 +275,7 @@ int serialize_geometry(struct serialization_state *sst, json_object *geometry, j
attrib.type = metatype[m - 1]; attrib.type = metatype[m - 1];
attrib.string = metaval[m - 1]; attrib.string = metaval[m - 1];
if (!filters) { if (!sst->filters) {
auto fk = layermap->find(layername); auto fk = layermap->find(layername);
add_to_file_keys(fk->second.file_keys, metakey[m - 1], attrib); add_to_file_keys(fk->second.file_keys, metakey[m - 1], attrib);
} }
@ -311,10 +311,10 @@ int serialize_geometry(struct serialization_state *sst, json_object *geometry, j
sf.full_values.push_back(sv); sf.full_values.push_back(sv);
} }
return serialize_feature(sst, sf, want_dist, filters, maxzoom, uses_gamma); return serialize_feature(sst, sf);
} }
int serialize_feature(struct serialization_state *sst, serial_feature &sf, bool want_dist, bool filters, int maxzoom, bool uses_gamma) { int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
struct reader *r = &(sst->readers[sst->segment]); struct reader *r = &(sst->readers[sst->segment]);
sf.bbox[0] = LLONG_MAX; sf.bbox[0] = LLONG_MAX;
@ -329,7 +329,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, bool
sf.geometry = fix_polygon(sf.geometry); sf.geometry = fix_polygon(sf.geometry);
} }
if (want_dist) { if (sst->want_dist) {
std::vector<unsigned long long> locs; std::vector<unsigned long long> locs;
for (size_t i = 0; i < sf.geometry.size(); i++) { for (size_t i = 0; i < sf.geometry.size(); i++) {
if (sf.geometry[i].op == VT_MOVETO || sf.geometry[i].op == VT_LINETO) { if (sf.geometry[i].op == VT_MOVETO || sf.geometry[i].op == VT_LINETO) {
@ -361,12 +361,12 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, bool
if (sf.geometry.size() > 0 && (sf.bbox[2] < sf.bbox[0] || sf.bbox[3] < sf.bbox[1])) { if (sf.geometry.size() > 0 && (sf.bbox[2] < sf.bbox[0] || sf.bbox[3] < sf.bbox[1])) {
fprintf(stderr, "Internal error: impossible feature bounding box %llx,%llx,%llx,%llx\n", sf.bbox[0], sf.bbox[1], sf.bbox[2], sf.bbox[3]); fprintf(stderr, "Internal error: impossible feature bounding box %llx,%llx,%llx,%llx\n", sf.bbox[0], sf.bbox[1], sf.bbox[2], sf.bbox[3]);
} }
if (sf.bbox[2] - sf.bbox[0] > (2LL << (32 - maxzoom)) || sf.bbox[3] - sf.bbox[1] > (2LL << (32 - maxzoom))) { if (sf.bbox[2] - sf.bbox[0] > (2LL << (32 - sst->maxzoom)) || sf.bbox[3] - sf.bbox[1] > (2LL << (32 - sst->maxzoom))) {
inline_meta = false; inline_meta = false;
if (prevent[P_CLIPPING]) { if (prevent[P_CLIPPING]) {
static volatile long long warned = 0; static volatile long long warned = 0;
long long extent = ((sf.bbox[2] - sf.bbox[0]) / ((1LL << (32 - maxzoom)) + 1)) * ((sf.bbox[3] - sf.bbox[1]) / ((1LL << (32 - maxzoom)) + 1)); long long extent = ((sf.bbox[2] - sf.bbox[0]) / ((1LL << (32 - sst->maxzoom)) + 1)) * ((sf.bbox[3] - sf.bbox[1]) / ((1LL << (32 - sst->maxzoom)) + 1));
if (extent > warned) { if (extent > warned) {
fprintf(stderr, "Warning: %s:%d: Large unclipped (-pc) feature may be duplicated across %lld tiles\n", sst->fname, sst->line, extent); fprintf(stderr, "Warning: %s:%d: Large unclipped (-pc) feature may be duplicated across %lld tiles\n", sst->fname, sst->line, extent);
warned = extent; warned = extent;
@ -420,7 +420,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, bool
long long midy = (sf.bbox[1] / 2 + sf.bbox[3] / 2) & ((1LL << 32) - 1); long long midy = (sf.bbox[1] / 2 + sf.bbox[3] / 2) & ((1LL << 32) - 1);
bbox_index = encode(midx, midy); bbox_index = encode(midx, midy);
if (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_CALCULATE_FEATURE_DENSITY] || additional[A_INCREASE_GAMMA_AS_NEEDED] || uses_gamma) { if (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_CALCULATE_FEATURE_DENSITY] || additional[A_INCREASE_GAMMA_AS_NEEDED] || sst->uses_gamma) {
sf.index = bbox_index; sf.index = bbox_index;
} else { } else {
sf.index = 0; sf.index = 0;
@ -493,7 +493,7 @@ void check_crs(json_object *j, const char *reading) {
} }
} }
void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int layer, double droprate, int maxzoom, std::map<std::string, layermap_entry> *layermap, std::string layername, bool uses_gamma, std::map<std::string, int> const *attribute_types, bool want_dist, bool filters) { void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int layer, std::map<std::string, layermap_entry> *layermap, std::string layername, std::map<std::string, int> const *attribute_types) {
long long found_hashes = 0; long long found_hashes = 0;
long long found_features = 0; long long found_features = 0;
long long found_geometries = 0; long long found_geometries = 0;
@ -561,7 +561,7 @@ void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::st
} }
found_geometries++; found_geometries++;
serialize_geometry(sst, j, NULL, NULL, exclude, include, exclude_all, basezoom, layer, droprate, NULL, maxzoom, j, layermap, layername, uses_gamma, attribute_types, want_dist, filters); serialize_geojson_feature(sst, j, NULL, NULL, exclude, include, exclude_all, basezoom, layer, NULL, j, layermap, layername, attribute_types);
json_free(j); json_free(j);
continue; continue;
} }
@ -604,10 +604,10 @@ void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::st
if (geometries != NULL) { if (geometries != NULL) {
size_t g; size_t g;
for (g = 0; g < geometries->length; g++) { for (g = 0; g < geometries->length; g++) {
serialize_geometry(sst, geometries->array[g], properties, id, exclude, include, exclude_all, basezoom, layer, droprate, tippecanoe, maxzoom, j, layermap, layername, uses_gamma, attribute_types, want_dist, filters); serialize_geojson_feature(sst, geometries->array[g], properties, id, exclude, include, exclude_all, basezoom, layer, tippecanoe, j, layermap, layername, attribute_types);
} }
} else { } else {
serialize_geometry(sst, geometry, properties, id, exclude, include, exclude_all, basezoom, layer, droprate, tippecanoe, maxzoom, j, layermap, layername, uses_gamma, attribute_types, want_dist, filters); serialize_geojson_feature(sst, geometry, properties, id, exclude, include, exclude_all, basezoom, layer, tippecanoe, j, layermap, layername, attribute_types);
} }
json_free(j); json_free(j);
@ -619,7 +619,7 @@ void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::st
void *run_parse_json(void *v) { void *run_parse_json(void *v) {
struct parse_json_args *pja = (struct parse_json_args *) v; struct parse_json_args *pja = (struct parse_json_args *) v;
parse_json(pja->sst, pja->jp, pja->exclude, pja->include, pja->exclude_all, pja->basezoom, pja->layer, pja->droprate, pja->maxzoom, pja->layermap, *pja->layername, pja->uses_gamma, pja->attribute_types, pja->want_dist, pja->filters); parse_json(pja->sst, pja->jp, pja->exclude, pja->include, pja->exclude_all, pja->basezoom, pja->layer, pja->layermap, *pja->layername, pja->attribute_types);
return NULL; return NULL;
} }

View File

@ -16,14 +16,10 @@ struct parse_json_args {
int exclude_all; int exclude_all;
int basezoom; int basezoom;
int layer; int layer;
double droprate;
int maxzoom;
std::map<std::string, layermap_entry> *layermap; std::map<std::string, layermap_entry> *layermap;
std::string *layername; std::string *layername;
bool uses_gamma;
std::map<std::string, int> const *attribute_types; std::map<std::string, int> const *attribute_types;
bool want_dist; bool want_dist;
bool filters;
struct serialization_state *sst; struct serialization_state *sst;
}; };
@ -31,7 +27,7 @@ struct parse_json_args {
struct json_pull *json_begin_map(char *map, long long len); struct json_pull *json_begin_map(char *map, long long len);
void json_end_map(struct json_pull *jp); void json_end_map(struct json_pull *jp);
void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int layer, double droprate, int maxzoom, std::map<std::string, layermap_entry> *layermap, std::string layername, bool uses_gamma, std::map<std::string, int> const *attribute_types, bool want_dist, bool filters); void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int layer, std::map<std::string, layermap_entry> *layermap, std::string layername, std::map<std::string, int> const *attribute_types);
void *run_parse_json(void *v); void *run_parse_json(void *v);
#endif #endif

View File

@ -394,6 +394,10 @@ void do_read_parallel(char *map, long long len, long long initial_offset, const
sst[i].initial_y = &initial_y[i]; sst[i].initial_y = &initial_y[i];
sst[i].dist_sum = &(dist_sums[i]); sst[i].dist_sum = &(dist_sums[i]);
sst[i].dist_count = &(dist_counts[i]); sst[i].dist_count = &(dist_counts[i]);
sst[i].want_dist = want_dist;
sst[i].maxzoom = maxzoom;
sst[i].uses_gamma = uses_gamma;
sst[i].filters = filters;
pja[i].jp = json_begin_map(map + segs[i], segs[i + 1] - segs[i]); pja[i].jp = json_begin_map(map + segs[i], segs[i + 1] - segs[i]);
pja[i].exclude = exclude; pja[i].exclude = exclude;
@ -401,14 +405,9 @@ void do_read_parallel(char *map, long long len, long long initial_offset, const
pja[i].exclude_all = exclude_all; pja[i].exclude_all = exclude_all;
pja[i].basezoom = basezoom; pja[i].basezoom = basezoom;
pja[i].layer = source; pja[i].layer = source;
pja[i].droprate = droprate;
pja[i].maxzoom = maxzoom;
pja[i].layermap = &(*layermaps)[i]; pja[i].layermap = &(*layermaps)[i];
pja[i].layername = &layername; pja[i].layername = &layername;
pja[i].uses_gamma = uses_gamma;
pja[i].attribute_types = attribute_types; pja[i].attribute_types = attribute_types;
pja[i].want_dist = want_dist;
pja[i].filters = filters;
pja[i].sst = &sst[i]; pja[i].sst = &sst[i];
@ -1374,8 +1373,12 @@ int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzo
sst.initialized = &initialized[0]; sst.initialized = &initialized[0];
sst.dist_sum = &dist_sum; sst.dist_sum = &dist_sum;
sst.dist_count = &dist_count; sst.dist_count = &dist_count;
sst.want_dist = guess_maxzoom;
sst.maxzoom = maxzoom;
sst.filters = prefilter != NULL || postfilter != NULL;
sst.uses_gamma = uses_gamma;
parse_json(&sst, jp, exclude, include, exclude_all, basezoom, layer, droprate, maxzoom, &layermaps[0], sources[layer].layer, uses_gamma, attribute_types, guess_maxzoom, prefilter != NULL || postfilter != NULL); parse_json(&sst, jp, exclude, include, exclude_all, basezoom, layer, &layermaps[0], sources[layer].layer, attribute_types);
json_end(jp); json_end(jp);
overall_offset = layer_seq; overall_offset = layer_seq;
checkdisk(reader, CPUS); checkdisk(reader, CPUS);

View File

@ -109,6 +109,11 @@ struct serialization_state {
double *dist_sum; // running tally for calculation of resolution within features double *dist_sum; // running tally for calculation of resolution within features
size_t *dist_count; size_t *dist_count;
bool want_dist;
int maxzoom;
bool filters;
bool uses_gamma;
}; };
#endif #endif