mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 01:45:41 +02:00
Merge pull request #80 from mapbox/preserve-sequence
Add a flag to preserve the original order of the features from the input
This commit is contained in:
@@ -96,6 +96,7 @@ Options
|
|||||||
* -pf: Don't limit tiles to 200,000 features
|
* -pf: Don't limit tiles to 200,000 features
|
||||||
* -pk: Don't limit tiles to 500K bytes
|
* -pk: Don't limit tiles to 500K bytes
|
||||||
* -pd: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries.
|
* -pd: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries.
|
||||||
|
* -pi: Preserve the original input order of features as the drawing order instead of ordering geographically. (This is implemented as a restoration of the original order at the end, so that dot-dropping is still geographic, which means it also undoes -ao).
|
||||||
* -q: Work quietly instead of reporting progress
|
* -q: Work quietly instead of reporting progress
|
||||||
|
|
||||||
Example
|
Example
|
||||||
|
|||||||
@@ -499,6 +499,7 @@ int serialize_geometry(json_object *geometry, json_object *properties, const cha
|
|||||||
long long geomstart = *geompos;
|
long long geomstart = *geompos;
|
||||||
|
|
||||||
serialize_byte(geomfile, mb_geometry[t], geompos, fname);
|
serialize_byte(geomfile, mb_geometry[t], geompos, fname);
|
||||||
|
serialize_long_long(geomfile, *seq, geompos, fname);
|
||||||
serialize_long_long(geomfile, n, geompos, fname);
|
serialize_long_long(geomfile, n, geompos, fname);
|
||||||
serialize_long_long(geomfile, metastart, geompos, fname);
|
serialize_long_long(geomfile, metastart, geompos, fname);
|
||||||
long long wx = initial_x, wy = initial_y;
|
long long wx = initial_x, wy = initial_y;
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ it encounters.
|
|||||||
.IP \(bu 2
|
.IP \(bu 2
|
||||||
\-pd: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries.
|
\-pd: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries.
|
||||||
.IP \(bu 2
|
.IP \(bu 2
|
||||||
|
\-pi: Preserve the original input order of features as the drawing order instead of ordering geographically. (This is implemented as a restoration of the original order at the end, so that dot\-dropping is still geographic, which means it also undoes \-ao).
|
||||||
|
.IP \(bu 2
|
||||||
\-q: Work quietly instead of reporting progress
|
\-q: Work quietly instead of reporting progress
|
||||||
.RE
|
.RE
|
||||||
.SH Example
|
.SH Example
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ struct coalesce {
|
|||||||
unsigned long long index2;
|
unsigned long long index2;
|
||||||
char *metasrc;
|
char *metasrc;
|
||||||
bool coalesced;
|
bool coalesced;
|
||||||
|
long long original_seq;
|
||||||
|
|
||||||
bool operator<(const coalesce &o) const {
|
bool operator<(const coalesce &o) const {
|
||||||
int cmp = coalindexcmp(this, &o);
|
int cmp = coalindexcmp(this, &o);
|
||||||
@@ -144,6 +145,12 @@ struct coalesce {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct preservecmp {
|
||||||
|
bool operator()(struct coalesce &a, struct coalesce &b) {
|
||||||
|
return a.original_seq < b.original_seq;
|
||||||
|
}
|
||||||
|
} preservecmp;
|
||||||
|
|
||||||
int coalcmp(const void *v1, const void *v2) {
|
int coalcmp(const void *v1, const void *v2) {
|
||||||
const struct coalesce *c1 = (const struct coalesce *) v1;
|
const struct coalesce *c1 = (const struct coalesce *) v1;
|
||||||
const struct coalesce *c2 = (const struct coalesce *) v2;
|
const struct coalesce *c2 = (const struct coalesce *) v2;
|
||||||
@@ -362,7 +369,7 @@ void evaluate(std::vector<coalesce> &features, char *metabase, struct pool *file
|
|||||||
}
|
}
|
||||||
#endif
|
#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) {
|
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) {
|
||||||
if (geom.size() > 0 && nextzoom <= file_maxzoom) {
|
if (geom.size() > 0 && nextzoom <= file_maxzoom) {
|
||||||
int xo, yo;
|
int xo, yo;
|
||||||
int span = 1 << (nextzoom - z);
|
int span = 1 << (nextzoom - z);
|
||||||
@@ -428,6 +435,7 @@ void rewrite(drawvec &geom, int z, int nextzoom, int file_maxzoom, long long *bb
|
|||||||
|
|
||||||
// printf("type %d, meta %lld\n", t, metastart);
|
// printf("type %d, meta %lld\n", t, metastart);
|
||||||
serialize_byte(geomfile[j], t, &geompos[j], fname);
|
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, &geompos[j], fname);
|
||||||
serialize_long_long(geomfile[j], metastart, &geompos[j], fname);
|
serialize_long_long(geomfile[j], metastart, &geompos[j], fname);
|
||||||
long long wx = initial_x, wy = initial_y;
|
long long wx = initial_x, wy = initial_y;
|
||||||
@@ -518,6 +526,9 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long long original_seq;
|
||||||
|
deserialize_long_long(geoms, &original_seq);
|
||||||
|
|
||||||
long long layer;
|
long long layer;
|
||||||
deserialize_long_long(geoms, &layer);
|
deserialize_long_long(geoms, &layer);
|
||||||
|
|
||||||
@@ -565,7 +576,7 @@ 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 */
|
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);
|
rewrite(geom, z, nextzoom, file_maxzoom, bbox, tx, ty, buffer, line_detail, within, geompos, geomfile, fname, t, layer, metastart, feature_minzoom, original_seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (z < file_minzoom) {
|
if (z < file_minzoom) {
|
||||||
@@ -672,6 +683,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f
|
|||||||
c.geom = geom;
|
c.geom = geom;
|
||||||
c.metasrc = meta;
|
c.metasrc = meta;
|
||||||
c.coalesced = false;
|
c.coalesced = false;
|
||||||
|
c.original_seq = original_seq;
|
||||||
|
|
||||||
decode_meta(&meta, stringpool, keys[layer], values[layer], file_keys[layer], &c.meta, NULL);
|
decode_meta(&meta, stringpool, keys[layer], values[layer], file_keys[layer], &c.meta, NULL);
|
||||||
features[layer].push_back(c);
|
features[layer].push_back(c);
|
||||||
@@ -720,6 +732,10 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f
|
|||||||
features[j][x].geom = simplify_lines(features[j][x].geom, 32, 0);
|
features[j][x].geom = simplify_lines(features[j][x].geom, 32, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prevent['i' & 0xFF]) {
|
||||||
|
std::sort(features[j].begin(), features[j].end(), preservecmp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (z == 0 && unclipped_features < original_features / 2) {
|
if (z == 0 && unclipped_features < original_features / 2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user