mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-23 02:22:34 +00:00
Split more serialization details out from being parsing parameters
This commit is contained in:
parent
b114e22d39
commit
ed8fbd0236
30
geojson.cpp
30
geojson.cpp
@ -38,7 +38,7 @@
|
||||
#include "read_json.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) {
|
||||
long long offset = 0;
|
||||
@ -99,7 +99,7 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox
|
||||
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");
|
||||
if (geometry_type == NULL) {
|
||||
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 (layermap->count(tippecanoe_layername) == 0) {
|
||||
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.string = metaval[m - 1];
|
||||
|
||||
if (!filters) {
|
||||
if (!sst->filters) {
|
||||
auto fk = layermap->find(layername);
|
||||
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);
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (want_dist) {
|
||||
if (sst->want_dist) {
|
||||
std::vector<unsigned long long> locs;
|
||||
for (size_t i = 0; i < sf.geometry.size(); i++) {
|
||||
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])) {
|
||||
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;
|
||||
|
||||
if (prevent[P_CLIPPING]) {
|
||||
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) {
|
||||
fprintf(stderr, "Warning: %s:%d: Large unclipped (-pc) feature may be duplicated across %lld tiles\n", sst->fname, sst->line, 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);
|
||||
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;
|
||||
} else {
|
||||
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_features = 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++;
|
||||
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
@ -604,10 +604,10 @@ void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::st
|
||||
if (geometries != NULL) {
|
||||
size_t 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 {
|
||||
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);
|
||||
@ -619,7 +619,7 @@ void parse_json(struct serialization_state *sst, json_pull *jp, std::set<std::st
|
||||
void *run_parse_json(void *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;
|
||||
}
|
||||
|
@ -16,14 +16,10 @@ struct parse_json_args {
|
||||
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;
|
||||
|
||||
struct serialization_state *sst;
|
||||
};
|
||||
@ -31,7 +27,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<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);
|
||||
|
||||
#endif
|
||||
|
15
main.cpp
15
main.cpp
@ -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].dist_sum = &(dist_sums[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].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].basezoom = basezoom;
|
||||
pja[i].layer = source;
|
||||
pja[i].droprate = droprate;
|
||||
pja[i].maxzoom = maxzoom;
|
||||
pja[i].layermap = &(*layermaps)[i];
|
||||
pja[i].layername = &layername;
|
||||
pja[i].uses_gamma = uses_gamma;
|
||||
pja[i].attribute_types = attribute_types;
|
||||
pja[i].want_dist = want_dist;
|
||||
pja[i].filters = filters;
|
||||
|
||||
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.dist_sum = &dist_sum;
|
||||
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);
|
||||
overall_offset = layer_seq;
|
||||
checkdisk(reader, CPUS);
|
||||
|
@ -109,6 +109,11 @@ struct serialization_state {
|
||||
|
||||
double *dist_sum; // running tally for calculation of resolution within features
|
||||
size_t *dist_count;
|
||||
bool want_dist;
|
||||
|
||||
int maxzoom;
|
||||
bool filters;
|
||||
bool uses_gamma;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user