Add a tippecanoe-specific GeoJSON extension for feature minzoom and maxzoom.

This commit is contained in:
Eric Fischer
2015-10-06 16:51:23 -07:00
parent c4f517fbdc
commit c0480673c5
2 changed files with 60 additions and 14 deletions
+24 -3
View File
@@ -369,7 +369,7 @@ void evaluate(std::vector<coalesce> &features, char *metabase, struct pool *file
}
#endif
void rewrite(drawvec &geom, int z, int nextzoom, int file_maxzoom, long long *bbox, unsigned tx, unsigned ty, int buffer, int line_detail, int *within, long long *geompos, FILE **geomfile, const char *fname, signed char t, int layer, long long metastart, signed char feature_minzoom, long long seq) {
void rewrite(drawvec &geom, int z, int nextzoom, int file_maxzoom, long long *bbox, unsigned tx, unsigned ty, int buffer, int line_detail, int *within, long long *geompos, FILE **geomfile, const char *fname, signed char t, int layer, long long metastart, signed char feature_minzoom, long long seq, int tippecanoe_minzoom, int tippecanoe_maxzoom) {
if (geom.size() > 0 && nextzoom <= file_maxzoom) {
int xo, yo;
int span = 1 << (nextzoom - z);
@@ -436,7 +436,13 @@ void rewrite(drawvec &geom, int z, int nextzoom, int file_maxzoom, long long *bb
// printf("type %d, meta %lld\n", t, metastart);
serialize_byte(geomfile[j], t, &geompos[j], fname);
serialize_long_long(geomfile[j], seq, &geompos[j], fname);
serialize_long_long(geomfile[j], layer, &geompos[j], fname);
serialize_long_long(geomfile[j], (layer << 2) | ((tippecanoe_minzoom != -1) << 1) | (tippecanoe_maxzoom != -1), &geompos[j], fname);
if (tippecanoe_minzoom != -1) {
serialize_int(geomfile[j], tippecanoe_minzoom, geompos, fname);
}
if (tippecanoe_maxzoom != -1) {
serialize_int(geomfile[j], tippecanoe_maxzoom, geompos, fname);
}
serialize_long_long(geomfile[j], metastart, &geompos[j], fname);
long long wx = initial_x, wy = initial_y;
@@ -531,6 +537,14 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f
long long layer;
deserialize_long_long(geoms, &layer);
int tippecanoe_minzoom = -1, tippecanoe_maxzoom = -1;
if (layer & 2) {
deserialize_int(geoms, &tippecanoe_minzoom);
}
if (layer & 1) {
deserialize_int(geoms, &tippecanoe_maxzoom);
}
layer >>= 2;
long long metastart;
deserialize_long_long(geoms, &metastart);
@@ -576,13 +590,20 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f
}
if (line_detail == detail && fraction == 1) { /* only write out the next zoom once, even if we retry */
rewrite(geom, z, nextzoom, file_maxzoom, bbox, tx, ty, buffer, line_detail, within, geompos, geomfile, fname, t, layer, metastart, feature_minzoom, original_seq);
rewrite(geom, z, nextzoom, file_maxzoom, bbox, tx, ty, buffer, line_detail, within, geompos, geomfile, fname, t, layer, metastart, feature_minzoom, original_seq, tippecanoe_minzoom, tippecanoe_maxzoom);
}
if (z < file_minzoom) {
continue;
}
if (tippecanoe_minzoom != -1 && z < tippecanoe_minzoom) {
continue;
}
if (tippecanoe_maxzoom != -1 && z > tippecanoe_maxzoom) {
continue;
}
if (t == VT_LINE && z + line_detail <= feature_minzoom) {
continue;
}