mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-02 01:08:14 +00:00
Add a flag to dynamically drop a fraction of features from large tiles
This commit is contained in:
parent
9e162e6f8f
commit
555ababd2e
@ -85,6 +85,7 @@ Options
|
||||
* -pk: Don't limit tiles to 500K bytes
|
||||
* -po: Don't reorder features to put the same properties in sequence
|
||||
* -pl: Let "dot" simplification apply to lines too
|
||||
* -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.
|
||||
|
||||
Example
|
||||
-------
|
||||
|
16
tile.cc
16
tile.cc
@ -354,6 +354,7 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
||||
int line_detail;
|
||||
static bool evaluated = false;
|
||||
double oprogress = 0;
|
||||
double fraction = 1;
|
||||
|
||||
char *og = *geoms;
|
||||
|
||||
@ -381,6 +382,8 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
||||
interval = exp(log(droprate) * (basezoom - z));
|
||||
}
|
||||
|
||||
double fraction_accum = 0;
|
||||
|
||||
unsigned long long previndex = 0;
|
||||
double scale = (double) (1LL << (64 - 2 * (z + 8)));
|
||||
double gap = 0;
|
||||
@ -552,6 +555,12 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
||||
}
|
||||
}
|
||||
|
||||
fraction_accum += fraction;
|
||||
if (fraction_accum < 1) {
|
||||
continue;
|
||||
}
|
||||
fraction_accum -= 1;
|
||||
|
||||
bool reduced = false;
|
||||
if (t == VT_POLYGON) {
|
||||
geom = reduce_tiny_poly(geom, z, line_detail, &reduced, &accum_area);
|
||||
@ -611,7 +620,7 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
||||
}
|
||||
|
||||
for (j = 0; j < nlayers; j++) {
|
||||
if (!prevent['o'] & 0xFF) {
|
||||
if (!prevent['o' & 0xFF]) {
|
||||
std::sort(features[j].begin(), features[j].end());
|
||||
}
|
||||
|
||||
@ -681,6 +690,11 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
||||
evaluate(features[0], metabase, file_keys[0], layername, line_detail, compressed.size()); // XXX layer
|
||||
#endif
|
||||
}
|
||||
|
||||
if (prevent['d' & 0xFF]) {
|
||||
fraction = fraction * 500000 / compressed.size();
|
||||
fprintf(stderr, "Going to try keeping %0.2f%% of the features to make it fit\n", fraction * 100);
|
||||
}
|
||||
} else {
|
||||
mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size());
|
||||
return count;
|
||||
|
Loading…
x
Reference in New Issue
Block a user