Compare commits

..
Author SHA1 Message Date
Erica Fischer 3a65db7a22 Also pay attention to area vs. prominence with polygon dust 2022-10-19 14:48:30 -07:00
Erica Fischer 2024af2047 I had the comparison backwards 2022-10-19 14:40:50 -07:00
Erica Fischer ebdf5ddce9 Add option to order by estimated prominence 2022-10-19 13:57:28 -07:00
Erica Fischer 8e8154339f Change all these places where I said "extent" but really meant "area" 2022-10-19 11:53:47 -07:00
Erica Fischer b763625862 Add an option to generate label points in place of polygons (#20)
* Add an option to generate label points in place of polygons

* Change all these places where I said "extent" but really meant "area"

* Revert "Change all these places where I said "extent" but really meant "area""

This reverts commit 403828d2f7.

* Add --order-smallest-first and --order-largest-first options

* Use Turf's center-of-mass algorithm for polygon label points

* If the label point isn't within the polygon, find one that is

* Don't choose a label point that is too close to a border

* Try a little harder to find an optimal label point

* Checkerboard which tiles labels are generated in, to reduce adjacency

* Use a label point for the general representative point for polygons

(Skipping the iteration to find one that is as far as possible from
the borders)

This makes the labels look better in many cases (like France at z1)
but unfortunately ripples into changing the sequence of polygons in
many tests, so the diff is big.

* Revert "Use a label point for the general representative point for polygons"

This reverts commit 2261adf05e.

* Checkpoint work on spiral labels

* Clip label spirals to the feature bounds

* Fix label test

* Be careful not to place spiral labels too close to borders either

* For spiral anchors, only check tile scale, not feature size

* Update test

* Only try to find a central label point for the largest ring

* In tiny polygon dust, keep the attributes of the largest feature
2022-10-13 14:21:36 -07:00
18 changed files with 1384 additions and 519 deletions
+1
View File
@@ -2,6 +2,7 @@
* Add an option to generate label points in place of polygons
* Add --order-smallest-first and --order-largest-first options
* When tiny polygons are being aggregated into dust, keep the attributes of the largest.
## 2.8.1
+2
View File
@@ -508,6 +508,8 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
* `--order-descending-by=`_attribute_: Order features by the specified _attribute_, in reverse alphabetical or numerical order. Multiple `--order-by` and `--order-descending-by` options may be specified, the first being the primary sort key.
* `--order-smallest-first`: Order features so the smallest geometry comes first in each tile. Multiple `--order-by` and `--order-descending-by` options may be specified, the first being the primary sort key.
* `--order-largest-first`: Order features so the largest geometry comes first in each tile. Multiple `--order-by` and `--order-descending-by` options may be specified, the first being the primary sort key.
* `--order-prominent-first`: Order features so the most prominent geometry (a combination of size and complexity) comes first in each tile. Multiple `--order-by` and `--order-descending-by` options may be specified, the first being the primary sort key.
* `--order-prominent-last`: Order features so the most prominent geometry (a combination of size and complexity) comes last in each tile. Multiple `--order-by` and `--order-descending-by` options may be specified, the first being the primary sort key.
### Adding calculated attributes
+1 -1
View File
@@ -212,7 +212,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::set<std::st
} else if (coordinate_mode == 2) { // integer
scale = 1;
}
layer_to_geojson(layer, z, x, y, !pipeline, pipeline, pipeline, false, 0, 0, 0, !force, state, scale);
layer_to_geojson(layer, z, x, y, !pipeline, pipeline, pipeline, false, 0, 0, 0, 0, !force, state, scale);
if (!pipeline) {
if (true) {
+2
View File
@@ -19,3 +19,5 @@
#define EXIT_UNLINK 118
#define EXIT_UTF8 119
#define EXIT_WRITE 120
// avoid 124, 125, 126, 127, 137, which are used by GNU timeout
+204 -83
View File
@@ -590,9 +590,11 @@ drawvec simple_clip_poly(drawvec &geom, int z, int buffer) {
return simple_clip_poly(geom, -clip_buffer, -clip_buffer, area + clip_buffer, area + clip_buffer);
}
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area) {
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature) {
drawvec out;
const double pixel = (1LL << (32 - detail - z)) * (double) tiny_polygon_size;
bool includes_real = false;
bool includes_dust = false;
*reduced = true;
bool included_last_outer = false;
@@ -636,6 +638,7 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
out.push_back(draw(VT_LINETO, geom[i].x - pixel / 2 + pixel, geom[i].y - pixel / 2 + pixel));
out.push_back(draw(VT_LINETO, geom[i].x - pixel / 2, geom[i].y - pixel / 2 + pixel));
out.push_back(draw(VT_LINETO, geom[i].x - pixel / 2, geom[i].y - pixel / 2));
includes_dust = true;
*accum_area -= pixel * pixel;
}
@@ -655,6 +658,7 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
// which means that the overall polygon has a real geometry,
// which means that it gets to be simplified.
*reduced = false;
includes_real = true;
if (area > 0) {
included_last_outer = true;
@@ -672,6 +676,41 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
fprintf(stderr, "\n");
out.push_back(geom[i]);
includes_real = true;
}
}
if (!includes_real) {
if (includes_dust) {
// this geometry is just dust, so if there is another feature that
// contributed to the dust that is larger than this feature,
// keep its attributes instead of this one that just happened to be
// the one that hit the threshold of survival.
if (order_by_prominence) {
if (tiny_feature->prominence > this_feature->prominence) {
*this_feature = *tiny_feature;
tiny_feature->prominence = 0;
}
} else if (order_by_size) {
if (tiny_feature->area > this_feature->area) {
*this_feature = *tiny_feature;
tiny_feature->area = 0;
}
}
} else {
// this is a feature that we are throwing away, so hang on to it
// attributes if it is bigger than the biggest one we threw away so far
if (order_by_prominence) {
if (this_feature->prominence > tiny_feature->prominence) {
*tiny_feature = *this_feature;
}
} else if (order_by_size) {
if (this_feature->area > tiny_feature->area) {
*tiny_feature = *this_feature;
}
}
}
}
@@ -1441,15 +1480,6 @@ draw centerOfMass(const drawvec &dv, size_t start, size_t end, draw centre) {
}
}
struct polygon_label {
long long size;
draw point;
bool operator<(const polygon_label &o) const {
return size > o.size; // reverse sort, largest first
}
};
double label_goodness(const drawvec &dv, size_t start, size_t count, long long x, long long y) {
if (!pnpoly(dv, start, count, x, y)) {
return 0; // outside the polygon is as bad as it gets
@@ -1488,8 +1518,8 @@ double label_goodness(const drawvec &dv, size_t start, size_t count, long long x
// least-bad option.
drawvec polygon_to_anchor(const drawvec &geom) {
std::vector<polygon_label> labels;
drawvec dv;
size_t start = 0, end = 0;
size_t best_area = 0;
for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) {
@@ -1500,85 +1530,176 @@ drawvec polygon_to_anchor(const drawvec &geom) {
}
}
long long xsum = 0;
long long ysum = 0;
size_t count = 0;
long long xmin = LLONG_MAX, ymin = LLONG_MAX, xmax = LLONG_MIN, ymax = LLONG_MIN;
double area = get_area(geom, i, j);
if (area > 0) { // don't generate anchors for holes
// Calculate centroid and bounding box.
// i + 1 to exclude the first point, which is duplicated as the last
for (size_t k = i + 1; k < j; k++) {
xsum += geom[k].x;
ysum += geom[k].y;
count++;
xmin = std::min(xmin, geom[k].x);
ymin = std::min(ymin, geom[k].y);
xmax = std::max(xmax, geom[k].x);
ymax = std::max(ymax, geom[k].y);
}
if (count > 0) {
draw centroid(VT_MOVETO, xsum / count, ysum / count);
draw d = centerOfMass(geom, i, j, centroid);
double radius = sqrt(area / M_PI);
double goodness_threshold = radius / 5;
double goodness = label_goodness(geom, i, j - i - 1, d.x, d.y);
if (goodness < goodness_threshold) {
// Label is too close to the border or outside it,
// so try some other possible points
for (long long sub = 2;
sub < 32 && (xmax - xmin) > 2 * sub && (ymax - ymin) > 2 * sub;
sub *= 2) {
for (long long x = 1; x < sub; x++) {
for (long long y = 1; y < sub; y++) {
draw maybe(VT_MOVETO,
xmin + x * (xmax - xmin) / sub,
ymin + y * (ymax - ymin) / sub);
double maybe_goodness = label_goodness(geom, i, j - i, maybe.x, maybe.y);
if (maybe_goodness > goodness) {
// better than the previous
d = maybe;
goodness = maybe_goodness;
}
}
}
if (goodness > goodness_threshold) {
break;
}
}
// There is nothing really good. Is the centroid maybe better?
// If not, we're stuck with whatever the best we found was.
if (label_goodness(geom, i, j - i, centroid.x, centroid.y) > goodness) {
d = centroid;
}
}
polygon_label pl;
pl.size = area;
pl.point = d;
labels.push_back(pl);
}
if (area > best_area) {
start = i;
end = j;
best_area = area;
}
i = j - 1;
}
}
std::sort(labels.begin(), labels.end());
if (best_area > 0) {
long long xsum = 0;
long long ysum = 0;
size_t count = 0;
long long xmin = LLONG_MAX, ymin = LLONG_MAX, xmax = LLONG_MIN, ymax = LLONG_MIN;
if (labels.size() > 0) {
dv.push_back(labels[0].point);
// Calculate centroid and bounding box.
// start + 1 to exclude the first point, which is duplicated as the last
for (size_t k = start + 1; k < end; k++) {
xsum += geom[k].x;
ysum += geom[k].y;
count++;
xmin = std::min(xmin, geom[k].x);
ymin = std::min(ymin, geom[k].y);
xmax = std::max(xmax, geom[k].x);
ymax = std::max(ymax, geom[k].y);
}
if (count > 0) {
draw centroid(VT_MOVETO, xsum / count, ysum / count);
draw d = centerOfMass(geom, start, end, centroid);
double radius = sqrt(best_area / M_PI);
double goodness_threshold = radius / 5;
double goodness = label_goodness(geom, start, end - start - 1, d.x, d.y);
if (goodness < goodness_threshold) {
// Label is too close to the border or outside it,
// so try some other possible points
for (long long sub = 2;
sub < 32 && (xmax - xmin) > 2 * sub && (ymax - ymin) > 2 * sub;
sub *= 2) {
for (long long x = 1; x < sub; x++) {
for (long long y = 1; y < sub; y++) {
draw maybe(VT_MOVETO,
xmin + x * (xmax - xmin) / sub,
ymin + y * (ymax - ymin) / sub);
double maybe_goodness = label_goodness(geom, start, end - start, maybe.x, maybe.y);
if (maybe_goodness > goodness) {
// better than the previous
d = maybe;
goodness = maybe_goodness;
}
}
}
if (goodness > goodness_threshold) {
break;
}
}
// There is nothing really good. Is the centroid maybe better?
// If not, we're stuck with whatever the best we found was.
if (label_goodness(geom, start, end - start, centroid.x, centroid.y) > goodness) {
d = centroid;
}
}
drawvec dv;
dv.push_back(d);
return dv;
}
}
return dv;
return drawvec();
}
static double dist(long long x1, long long y1, long long x2, long long y2) {
double dx = x2 - x1;
double dy = y2 - y1;
return sqrt(dx * dx + dy * dy);
}
drawvec spiral_anchors(drawvec const &geom, int tx, int ty, int z, unsigned long long label_point) {
drawvec out;
// anchor point in world coordinates
unsigned wx, wy;
decode_index(label_point, &wx, &wy);
// upper left of tile in world coordinates
long long tx1 = 0, ty1 = 0;
// lower right of tile in world coordinates;
long long tx2 = 1LL << 32, ty2 = 1LL << 32;
if (z != 0) {
tx1 = (long long) tx << (32 - z);
ty1 = (long long) ty << (32 - z);
tx2 = (long long) (tx + 1) << (32 - z);
ty2 = (long long) (ty + 1) << (32 - z);
}
// min and max distance of corners of this tile from the label point
double min_radius, max_radius;
if (wx >= tx1 && wx <= tx2 && wy >= ty1 && wy <= ty2) {
// center is in this tile,
// so min is 0, max can't be more than sqrt(2) tiles
min_radius = 0;
max_radius = sqrt(2);
} else {
// center is elsewhere,
// so min is at most sqrt(2)/2 tiles short of the center of the tile
// and max is at most sqrt(2)/2 tiles past the center of the tile
min_radius = std::max(0.0, dist(wx, wy, (tx1 + tx2) / 2, (ty1 + ty2) / 2) / (1LL << (32 - z)) - sqrt(2) / 2);
max_radius = min_radius + sqrt(2);
}
// labels complete a circle every 0.4 tiles of radius
const double spiral_dist = 0.4;
size_t min_i = pow(min_radius / spiral_dist, 2);
size_t max_i = pow(max_radius / spiral_dist, 2);
// https://craftofcoding.wordpress.com/tag/sunflower-spiral/
double angle = M_PI * (3.0 - sqrt(5.0)); // 137.5 in radians
for (size_t i = min_i; i <= max_i; i++) {
double r = sqrt(i) * spiral_dist;
double theta = i * angle;
// Convert polar to cartesian
long long x = r * cos(theta) * (1LL << (32 - z)) + wx;
long long y = r * sin(theta) * (1LL << (32 - z)) + wy;
if (x >= tx1 && x <= tx2 && y >= ty1 && y <= ty2) {
// is it actually inside the bounding box of the feature? then keep it.
for (size_t a = 0; a < geom.size(); a++) {
if (geom[a].op == VT_MOVETO) {
size_t b;
for (b = a + 1; b < geom.size(); b++) {
if (geom[b].op != VT_LINETO) {
break;
}
}
// If it's the central label, it's the best we've got,
// so accept it in any case. If it's from the outer spiral,
// don't use it if it's too close to a border.
if (i == 0) {
out.push_back(draw(VT_MOVETO, x - tx1, y - ty1));
break;
} else {
double tilesize = 1LL << (32 - z);
double goodness_threshold = tilesize / 100;
if (label_goodness(geom, a, b - a, x - tx1, y - ty1) > goodness_threshold) {
out.push_back(draw(VT_MOVETO, x - tx1, y - ty1));
break;
}
}
a = b - 1;
}
}
}
}
return out;
}
+3 -1
View File
@@ -56,6 +56,7 @@ struct draw {
};
typedef std::vector<draw> drawvec;
struct serial_feature;
drawvec decode_geometry(FILE *meta, std::atomic<long long> *geompos, int z, unsigned tx, unsigned ty, long long *bbox, unsigned initial_x, unsigned initial_y);
void to_tile_scale(drawvec &geom, int z, int detail);
@@ -64,7 +65,7 @@ drawvec clip_point(drawvec &geom, int z, long long buffer);
drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip);
drawvec simple_clip_poly(drawvec &geom, int z, int buffer);
drawvec close_poly(drawvec &geom);
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area);
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature);
drawvec clip_lines(drawvec &geom, int z, long long buffer);
drawvec stairstep(drawvec &geom, int z, int detail);
bool point_within_tile(long long x, long long y, int z);
@@ -77,6 +78,7 @@ void check_polygon(drawvec &geom);
double get_area(const drawvec &geom, size_t i, size_t j);
double get_mp_area(drawvec &geom);
drawvec polygon_to_anchor(const drawvec &geom);
drawvec spiral_anchors(drawvec const &geom, int tx, int ty, int z, unsigned long long label_point);
drawvec simple_clip_poly(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
drawvec clip_lines(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
+9
View File
@@ -87,6 +87,7 @@ std::string attribute_for_id = "";
std::vector<order_field> order_by;
bool order_reverse;
bool order_by_size = false;
bool order_by_prominence = false;
int prevent[256];
int additional[256];
@@ -2754,6 +2755,8 @@ int main(int argc, char **argv) {
{"order-descending-by", required_argument, 0, '~'},
{"order-smallest-first", no_argument, 0, '~'},
{"order-largest-first", no_argument, 0, '~'},
{"order-prominent-first", no_argument, 0, '~'},
{"order-prominent-last", no_argument, 0, '~'},
{"Adding calculated attributes", 0, 0, 0},
{"calculate-feature-density", no_argument, &additional[A_CALCULATE_FEATURE_DENSITY], 1},
@@ -2896,6 +2899,12 @@ int main(int argc, char **argv) {
} else if (strcmp(opt, "order-largest-first") == 0) {
order_by.push_back(order_field(ORDER_BY_SIZE, true));
order_by_size = true;
} else if (strcmp(opt, "order-prominent-first") == 0) {
order_by.push_back(order_field(ORDER_BY_PROMINENCE, true));
order_by_prominence = true;
} else if (strcmp(opt, "order-prominent-last") == 0) {
order_by.push_back(order_field(ORDER_BY_PROMINENCE, false));
order_by_prominence = true;
} else if (strcmp(opt, "simplification-at-maximum-zoom") == 0) {
maxzoom_simplification = atof_require(optarg, "Mazoom simplification");
if (maxzoom_simplification <= 0) {
+2
View File
@@ -69,6 +69,8 @@ extern std::vector<order_field> order_by;
// not legal UTF-8, so can't appear as a real attribute name
#define ORDER_BY_SIZE "\200size"
extern bool order_by_size;
#define ORDER_BY_PROMINENCE "\200prominence"
extern bool order_by_prominence;
int mkstemp_cloexec(char *name);
FILE *fopen_oflag(const char *name, const char *mode, int oflag);
+4
View File
@@ -657,6 +657,10 @@ the line or polygon within one tile unit of its proper location. You can probabl
\fB\fC\-\-order\-smallest\-first\fR: Order features so the smallest geometry comes first in each tile. Multiple \fB\fC\-\-order\-by\fR and \fB\fC\-\-order\-descending\-by\fR options may be specified, the first being the primary sort key.
.IP \(bu 2
\fB\fC\-\-order\-largest\-first\fR: Order features so the largest geometry comes first in each tile. Multiple \fB\fC\-\-order\-by\fR and \fB\fC\-\-order\-descending\-by\fR options may be specified, the first being the primary sort key.
.IP \(bu 2
\fB\fC\-\-order\-prominent\-first\fR: Order features so the most prominent geometry (a combination of size and complexity) comes first in each tile. Multiple \fB\fC\-\-order\-by\fR and \fB\fC\-\-order\-descending\-by\fR options may be specified, the first being the primary sort key.
.IP \(bu 2
\fB\fC\-\-order\-prominent\-last\fR: Order features so the most prominent geometry (a combination of size and complexity) comes last in each tile. Multiple \fB\fC\-\-order\-by\fR and \fB\fC\-\-order\-descending\-by\fR options may be specified, the first being the primary sort key.
.RE
.SS Adding calculated attributes
.RS
+5 -5
View File
@@ -54,7 +54,7 @@ void *run_writer(void *a) {
json_writer state(fp);
for (size_t i = 0; i < wa->layers->size(); i++) {
layer_to_geojson((*(wa->layers))[i], wa->z, wa->x, wa->y, false, true, false, true, 0, 0, 0, true, state, 0);
layer_to_geojson((*(wa->layers))[i], wa->z, wa->x, wa->y, false, true, false, true, 0, 0, 0, 0, true, state, 0);
}
if (fclose(fp) != 0) {
@@ -400,7 +400,7 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
sf.index = 0;
sf.bbox[0] = sf.bbox[1] = LLONG_MAX;
sf.bbox[2] = sf.bbox[3] = LLONG_MIN;
sf.extent = 0;
sf.area = 0;
sf.metapos = 0;
sf.has_id = false;
@@ -422,9 +422,9 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
sf.seq = sequence->value.number.number;
}
json_object *extent = json_hash_get(tippecanoe, "extent");
if (extent != NULL && extent->type == JSON_NUMBER) {
sf.extent = extent->value.number.number;
json_object *area = json_hash_get(tippecanoe, "extent");
if (area != NULL && area->type == JSON_NUMBER) {
sf.area = area->value.number.number;
}
json_object *dropped = json_hash_get(tippecanoe, "dropped");
+41 -29
View File
@@ -192,12 +192,13 @@ static void write_geometry(drawvec const &dv, std::atomic<long long> *fpos, FILE
void serialize_feature(FILE *geomfile, serial_feature *sf, std::atomic<long long> *geompos, const char *fname, long long wx, long long wy, bool include_minzoom) {
serialize_byte(geomfile, sf->t, geompos, fname);
#define FLAG_LAYER 7
#define FLAG_LAYER 8
#define FLAG_PROMINENCE 7
#define FLAG_LABEL_POINT 6
#define FLAG_SEQ 5
#define FLAG_INDEX 4
#define FLAG_EXTENT 3
#define FLAG_AREA 3
#define FLAG_ID 2
#define FLAG_MINZOOM 1
#define FLAG_MAXZOOM 0
@@ -207,7 +208,8 @@ void serialize_feature(FILE *geomfile, serial_feature *sf, std::atomic<long long
layer |= (sf->label_point != 0) << FLAG_LABEL_POINT;
layer |= (sf->seq != 0) << FLAG_SEQ;
layer |= (sf->index != 0) << FLAG_INDEX;
layer |= (sf->extent != 0) << FLAG_EXTENT;
layer |= (sf->area != 0) << FLAG_AREA;
layer |= (sf->prominence != 0) << FLAG_PROMINENCE;
layer |= sf->has_id << FLAG_ID;
layer |= sf->has_tippecanoe_minzoom << FLAG_MINZOOM;
layer |= sf->has_tippecanoe_maxzoom << FLAG_MAXZOOM;
@@ -236,8 +238,11 @@ void serialize_feature(FILE *geomfile, serial_feature *sf, std::atomic<long long
if (sf->label_point != 0) {
serialize_ulong_long(geomfile, sf->label_point, geompos, fname);
}
if (sf->extent != 0) {
serialize_long_long(geomfile, sf->extent, geompos, fname);
if (sf->area != 0) {
serialize_long_long(geomfile, sf->area, geompos, fname);
}
if (sf->prominence != 0) {
serialize_long_long(geomfile, sf->prominence, geompos, fname);
}
serialize_long_long(geomfile, sf->metapos, geompos, fname);
@@ -290,7 +295,8 @@ serial_feature deserialize_feature(FILE *geoms, std::atomic<long long> *geompos_
sf.index = 0;
sf.label_point = 0;
sf.extent = 0;
sf.area = 0;
sf.prominence = 0;
sf.geometry = decode_geometry(geoms, geompos_in, z, tx, ty, sf.bbox, initial_x[sf.segment], initial_y[sf.segment]);
if (sf.layer & (1 << FLAG_INDEX)) {
@@ -299,8 +305,11 @@ serial_feature deserialize_feature(FILE *geoms, std::atomic<long long> *geompos_
if (sf.layer & (1 << FLAG_LABEL_POINT)) {
deserialize_ulong_long_io(geoms, &sf.label_point, geompos_in);
}
if (sf.layer & (1 << FLAG_EXTENT)) {
deserialize_long_long_io(geoms, &sf.extent, geompos_in);
if (sf.layer & (1 << FLAG_AREA)) {
deserialize_long_long_io(geoms, &sf.area, geompos_in);
}
if (sf.layer & (1 << FLAG_PROMINENCE)) {
deserialize_long_long_io(geoms, &sf.prominence, geompos_in);
}
sf.layer >>= FLAG_LAYER;
@@ -525,12 +534,12 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
if (prevent[P_CLIPPING]) {
static std::atomic<long long> warned(0);
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;
long long area = ((sf.bbox[2] - sf.bbox[0]) / ((1LL << (32 - sst->maxzoom)) + 1)) * ((sf.bbox[3] - sf.bbox[1]) / ((1LL << (32 - sst->maxzoom)) + 1));
if (area > warned) {
fprintf(stderr, "Warning: %s:%d: Large unclipped (-pc) feature may be duplicated across %lld tiles\n", sst->fname, sst->line, area);
warned = area;
if (extent > 10000) {
if (area > 10000) {
fprintf(stderr, "Exiting because this can't be right.\n");
exit(EXIT_IMPOSSIBLE);
}
@@ -538,8 +547,17 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
}
}
double extent = 0;
if (additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED] || order_by_size) {
double area = 0;
if (additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED] || order_by_size || order_by_prominence) {
double dist = 0;
for (size_t i = 1; i < scaled_geometry.size(); i++) {
if (scaled_geometry[i].op == VT_LINETO) {
double xd = SHIFT_LEFT(scaled_geometry[i].x - scaled_geometry[i - 1].x);
double yd = SHIFT_LEFT(scaled_geometry[i].y - scaled_geometry[i - 1].y);
dist += sqrt(xd * xd + yd * yd);
}
}
if (sf.t == VT_POLYGON) {
for (size_t i = 0; i < scaled_geometry.size(); i++) {
if (scaled_geometry[i].op == VT_MOVETO) {
@@ -550,30 +568,24 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
}
}
extent += SHIFT_LEFT(SHIFT_LEFT(1LL)) * get_area(scaled_geometry, i, j);
area += SHIFT_LEFT(SHIFT_LEFT(1LL)) * get_area(scaled_geometry, i, j);
i = j - 1;
}
}
} else if (sf.t == VT_LINE) {
double dist = 0;
for (size_t i = 1; i < scaled_geometry.size(); i++) {
if (scaled_geometry[i].op == VT_LINETO) {
double xd = SHIFT_LEFT(scaled_geometry[i].x - scaled_geometry[i - 1].x);
double yd = SHIFT_LEFT(scaled_geometry[i].y - scaled_geometry[i - 1].y);
dist += sqrt(xd * xd + yd * yd);
}
}
// treat lines as having the area of a circle with the line as diameter
extent = M_PI * (dist / 2) * (dist / 2);
area = M_PI * (dist / 2) * (dist / 2);
}
// VT_POINT extent will be calculated in write_tile from the distance between adjacent features.
sf.prominence = sqrt(dist * dist * area);
// VT_POINT area will be calculated in write_tile from the distance between adjacent features.
}
if (extent <= LLONG_MAX) {
sf.extent = (long long) extent;
if (area <= LLONG_MAX) {
sf.area = (long long) area;
} else {
sf.extent = LLONG_MAX;
sf.area = LLONG_MAX;
}
if (!prevent[P_INPUT_ORDER]) {
+2 -1
View File
@@ -57,7 +57,8 @@ struct serial_feature {
drawvec geometry = drawvec();
unsigned long long index = 0;
unsigned long long label_point = 0;
long long extent = 0;
long long area = 0;
long long prominence = 0;
std::vector<long long> keys{};
std::vector<long long> values{};
@@ -125,9 +125,9 @@
{ "type": "FeatureCollection", "properties": { "layer": "layer3115744778", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { "rule": "type: 2, [\"in\", \"$type\", \"Polygon\", \"LineString\", \"Point\"]" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.000000, 0.000000 ], [ 0.966797, 1.054628 ] ] } }
,
{ "type": "Feature", "properties": { "rule": "type: 3, [\"in\", \"$type\", \"Polygon\", \"LineString\", \"Point\"]" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.966797, 1.054628 ], [ 0.966797, 0.000000 ], [ 0.000000, 0.000000 ], [ 0.966797, 1.054628 ] ] ] } }
,
{ "type": "Feature", "properties": { "rule": "type: 1, [\"in\", \"$type\", \"Polygon\", \"LineString\", \"Point\"]" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
,
{ "type": "Feature", "properties": { "rule": "type: 3, [\"in\", \"$type\", \"Polygon\", \"LineString\", \"Point\"]" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.966797, 1.054628 ], [ 0.966797, 0.000000 ], [ 0.000000, 0.000000 ], [ 0.966797, 1.054628 ] ] ] } }
] }
,
{ "type": "FeatureCollection", "properties": { "layer": "layer328238911", "version": 2, "extent": 4096 }, "features": [
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+67 -142
View File
@@ -96,7 +96,8 @@ struct coalesce {
double spacing = 0;
bool has_id = false;
unsigned long long id = 0;
long long extent = 0;
long long area = 0;
long long prominence = 0;
bool operator<(const coalesce &o) const {
int cmp = coalindexcmp(this, &o);
@@ -254,7 +255,12 @@ static mvt_value find_attribute_value(const struct coalesce *c1, std::string key
if (key == ORDER_BY_SIZE) {
mvt_value v;
v.type = mvt_double;
v.numeric_value.double_value = c1->extent;
v.numeric_value.double_value = c1->area;
return v;
} else if (key == ORDER_BY_PROMINENCE) {
mvt_value v;
v.type = mvt_double;
v.numeric_value.double_value = c1->prominence;
return v;
}
@@ -324,7 +330,7 @@ struct ordercmp {
}
} ordercmp;
void rewrite(drawvec &geom, int z, int nextzoom, int maxzoom, long long *bbox, unsigned tx, unsigned ty, int buffer, int *within, std::atomic<long long> *geompos, FILE **geomfile, const char *fname, signed char t, int layer, long long metastart, signed char feature_minzoom, int child_shards, int max_zoom_increment, long long seq, int tippecanoe_minzoom, int tippecanoe_maxzoom, int segment, unsigned *initial_x, unsigned *initial_y, std::vector<long long> &metakeys, std::vector<long long> &metavals, bool has_id, unsigned long long id, unsigned long long index, unsigned long long label_point, long long extent) {
void rewrite(drawvec &geom, int z, int nextzoom, int maxzoom, long long *bbox, unsigned tx, unsigned ty, int buffer, int *within, std::atomic<long long> *geompos, FILE **geomfile, const char *fname, signed char t, int layer, long long metastart, signed char feature_minzoom, int child_shards, int max_zoom_increment, long long seq, int tippecanoe_minzoom, int tippecanoe_maxzoom, int segment, unsigned *initial_x, unsigned *initial_y, std::vector<long long> &metakeys, std::vector<long long> &metavals, bool has_id, unsigned long long id, unsigned long long index, unsigned long long label_point, long long area, long long prominence) {
if (geom.size() > 0 && (nextzoom <= maxzoom || additional[A_EXTEND_ZOOMS])) {
int xo, yo;
int span = 1 << (nextzoom - z);
@@ -415,7 +421,8 @@ void rewrite(drawvec &geom, int z, int nextzoom, int maxzoom, long long *bbox, u
sf.geometry = geom2;
sf.index = index;
sf.label_point = label_point;
sf.extent = extent;
sf.area = area;
sf.prominence = prominence;
sf.feature_minzoom = feature_minzoom;
if (metastart < 0) {
@@ -459,7 +466,8 @@ struct partial {
unsigned long long id = 0;
bool has_id = 0;
ssize_t renamed = 0;
long long extent = 0;
long long area = 0;
long long prominence = 0;
long long clustered = 0;
std::set<std::string> need_tilestats;
std::map<std::string, accum_state> attribute_accum_state;
@@ -1248,9 +1256,9 @@ unsigned long long choose_mingap(std::vector<unsigned long long> const &indices,
return top;
}
long long choose_minextent(std::vector<long long> &extents, double f) {
std::sort(extents.begin(), extents.end());
return extents[(extents.size() - 1) * (1 - f)];
long long choose_minarea(std::vector<long long> &areas, double f) {
std::sort(areas.begin(), areas.end());
return areas[(areas.size() - 1) * (1 - f)];
}
struct write_tile_args {
@@ -1290,8 +1298,8 @@ struct write_tile_args {
size_t passes = 0;
unsigned long long mingap = 0;
unsigned long long mingap_out = 0;
long long minextent = 0;
long long minextent_out = 0;
long long minarea = 0;
long long minarea_out = 0;
double fraction = 0;
double fraction_out = 0;
size_t tile_size_out = 0;
@@ -1431,7 +1439,7 @@ serial_feature next_feature(FILE *geoms, std::atomic<long long> *geompos_in, cha
if (*first_time && pass == 1) { /* only write out the next zoom once, even if we retry */
if (sf.tippecanoe_maxzoom == -1 || sf.tippecanoe_maxzoom >= nextzoom) {
rewrite(sf.geometry, z, nextzoom, maxzoom, sf.bbox, tx, ty, buffer, within, geompos, geomfile, fname, sf.t, sf.layer, sf.metapos, sf.feature_minzoom, child_shards, max_zoom_increment, sf.seq, sf.tippecanoe_minzoom, sf.tippecanoe_maxzoom, sf.segment, initial_x, initial_y, sf.keys, sf.values, sf.has_id, sf.id, sf.index, sf.label_point, sf.extent);
rewrite(sf.geometry, z, nextzoom, maxzoom, sf.bbox, tx, ty, buffer, within, geompos, geomfile, fname, sf.t, sf.layer, sf.metapos, sf.feature_minzoom, child_shards, max_zoom_increment, sf.seq, sf.tippecanoe_minzoom, sf.tippecanoe_maxzoom, sf.segment, initial_x, initial_y, sf.keys, sf.values, sf.has_id, sf.id, sf.index, sf.label_point, sf.area, sf.prominence);
}
}
@@ -1606,7 +1614,7 @@ void *run_prefilter(void *v) {
decode_meta(sf.keys, sf.values, rpa->stringpool + rpa->pool_off[sf.segment], tmp_layer, tmp_feature);
tmp_layer.features.push_back(tmp_feature);
layer_to_geojson(tmp_layer, 0, 0, 0, false, true, false, true, sf.index, sf.seq, sf.extent, true, state, 0);
layer_to_geojson(tmp_layer, 0, 0, 0, false, true, false, true, sf.index, sf.seq, sf.area, sf.prominence, true, state, 0);
}
if (fclose(rpa->prefilter_fp) != 0) {
@@ -1801,99 +1809,10 @@ static bool line_is_too_small(drawvec const &geometry, int z, int detail) {
return true;
}
static double dist(long long x1, long long y1, long long x2, long long y2) {
double dx = x2 - x1;
double dy = y2 - y1;
return sqrt(dx * dx + dy * dy);
}
drawvec spiral_anchors(drawvec const &geom, int tx, int ty, int z, unsigned long long label_point) {
drawvec out;
// anchor point in world coordinates
unsigned wx, wy;
decode_index(label_point, &wx, &wy);
// upper left of tile in world coordinates
long long tx1 = 0, ty1 = 0;
// lower right of tile in world coordinates;
long long tx2 = 1LL << 32, ty2 = 1LL << 32;
if (z != 0) {
tx1 = (long long) tx << (32 - z);
ty1 = (long long) ty << (32 - z);
tx2 = (long long) (tx + 1) << (32 - z);
ty2 = (long long) (ty + 1) << (32 - z);
}
// min and max distance of corners of this tile from the label point
double min_radius, max_radius;
if (wx >= tx1 && wx <= tx2 && wy >= ty1 && wy <= ty2) {
// center is in this tile
min_radius = 0;
} else {
// center is elsewhere
min_radius = std::min(dist(wx, wy, tx1, ty1),
std::min(dist(wx, wy, tx2, ty1),
std::min(dist(wx, wy, tx2, ty2),
dist(wx, wy, tx1, ty2))));
}
max_radius = std::max(dist(wx, wy, tx1, ty1),
std::max(dist(wx, wy, tx2, ty1),
std::max(dist(wx, wy, tx2, ty2),
dist(wx, wy, tx1, ty2))));
// from world coordinates to tiles
min_radius /= 1LL << (32 - z);
max_radius /= 1LL << (32 - z);
// labels complete a circle every 0.4 tiles of radius
const double spiral_dist = 0.4;
size_t min_i = pow(min_radius / spiral_dist, 2);
size_t max_i = pow(max_radius / spiral_dist, 2);
// https://craftofcoding.wordpress.com/tag/sunflower-spiral/
double angle = M_PI * (3.0 - sqrt(5.0)); // 137.5 in radians
for (size_t i = min_i; i <= max_i; i++) {
double r = sqrt(i) * spiral_dist;
double theta = i * angle;
// Convert polar to cartesian
long long x = r * cos(theta) * (1LL << (32 - z)) + wx;
long long y = r * sin(theta) * (1LL << (32 - z)) + wy;
if (x >= tx1 && x <= tx2 && y >= ty1 && y <= ty2) {
// is it actually inside the bounding box of the feature? then keep it.
for (size_t a = 0; a < geom.size(); a++) {
if (geom[a].op == VT_MOVETO) {
size_t b;
for (b = a + 1; b < geom.size(); b++) {
if (geom[b].op != VT_LINETO) {
break;
}
}
if (pnpoly(geom, a, b - a, x - tx1, y - ty1)) {
out.push_back(draw(VT_MOVETO, x - tx1, y - ty1));
break;
}
a = b - 1;
}
}
}
}
return out;
}
long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *metabase, char *stringpool, int z, const unsigned tx, const unsigned ty, const int detail, int min_detail, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, FILE **geomfile, int minzoom, int maxzoom, double todo, std::atomic<long long> *along, long long alongminus, double gamma, int child_shards, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, std::atomic<int> *running, double simplification, std::vector<std::map<std::string, layermap_entry>> *layermaps, std::vector<std::vector<std::string>> *layer_unmaps, size_t tiling_seg, size_t pass, size_t passes, unsigned long long mingap, long long minextent, double fraction, const char *prefilter, const char *postfilter, struct json_object *filter, write_tile_args *arg, atomic_strategy *strategy) {
long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *metabase, char *stringpool, int z, const unsigned tx, const unsigned ty, const int detail, int min_detail, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, FILE **geomfile, int minzoom, int maxzoom, double todo, std::atomic<long long> *along, long long alongminus, double gamma, int child_shards, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, std::atomic<int> *running, double simplification, std::vector<std::map<std::string, layermap_entry>> *layermaps, std::vector<std::vector<std::string>> *layer_unmaps, size_t tiling_seg, size_t pass, size_t passes, unsigned long long mingap, long long minarea, double fraction, const char *prefilter, const char *postfilter, struct json_object *filter, write_tile_args *arg, atomic_strategy *strategy) {
double merge_fraction = 1;
double mingap_fraction = 1;
double minextent_fraction = 1;
double minarea_fraction = 1;
static std::atomic<double> oprogress(0);
long long og = *geompos_in;
@@ -1931,7 +1850,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
double fraction_accum = 0;
unsigned long long previndex = 0, density_previndex = 0, merge_previndex = 0;
unsigned long long extent_previndex = 0;
unsigned long long area_previndex = 0;
double scale = (double) (1LL << (64 - 2 * (z + 8)));
double gap = 0, density_gap = 0;
double spacing = 0;
@@ -1942,7 +1861,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
std::vector<struct partial> partials;
std::map<std::string, std::vector<coalesce>> layers;
std::vector<unsigned long long> indices;
std::vector<long long> extents;
std::vector<long long> areas;
double coalesced_area = 0;
drawvec shared_nodes;
@@ -1973,6 +1892,8 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
FILE *prefilter_read_fp = NULL;
json_pull *prefilter_jp = NULL;
serial_feature tiny_feature;
if (z < minzoom) {
prefilter = NULL;
postfilter = NULL;
@@ -2048,17 +1969,19 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
}
if (sf.t == VT_POINT) {
if (extent_previndex >= sf.index) {
sf.extent = 1;
if (area_previndex >= sf.index) {
sf.area = 1;
sf.prominence = 1;
} else {
double radius = sqrt(sf.index - extent_previndex) / 4.0;
sf.extent = M_PI * radius * radius;
if (sf.extent < 1) {
sf.extent = 1;
double radius = sqrt(sf.index - area_previndex) / 4.0;
sf.area = M_PI * radius * radius;
if (sf.area < 1) {
sf.area = 1;
}
sf.prominence = sf.area;
}
extent_previndex = sf.index;
area_previndex = sf.index;
}
if (sf.dropped) {
@@ -2109,23 +2032,23 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
indices.push_back(sf.index);
if (sf.index - merge_previndex < mingap && find_partial(partials, sf, which_partial, layer_unmaps)) {
partials[which_partial].geoms.push_back(sf.geometry);
coalesced_area += sf.extent;
coalesced_area += sf.area;
preserve_attributes(arg->attribute_accum, sf, stringpool, pool_off, partials[which_partial]);
strategy->coalesced_as_needed++;
continue;
}
} else if (additional[A_DROP_SMALLEST_AS_NEEDED]) {
extents.push_back(sf.extent);
if (sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps)) {
areas.push_back(sf.area);
if (sf.area + coalesced_area <= minarea && find_partial(partials, sf, which_partial, layer_unmaps)) {
preserve_attributes(arg->attribute_accum, sf, stringpool, pool_off, partials[which_partial]);
strategy->dropped_as_needed++;
continue;
}
} else if (additional[A_COALESCE_SMALLEST_AS_NEEDED]) {
extents.push_back(sf.extent);
if (sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps)) {
areas.push_back(sf.area);
if (sf.area + coalesced_area <= minarea && find_partial(partials, sf, which_partial, layer_unmaps)) {
partials[which_partial].geoms.push_back(sf.geometry);
coalesced_area += sf.extent;
coalesced_area += sf.area;
preserve_attributes(arg->attribute_accum, sf, stringpool, pool_off, partials[which_partial]);
strategy->coalesced_as_needed++;
continue;
@@ -2148,7 +2071,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
if (fraction_accum < 1 && find_partial(partials, sf, which_partial, layer_unmaps)) {
if (additional[A_COALESCE_FRACTION_AS_NEEDED]) {
partials[which_partial].geoms.push_back(sf.geometry);
coalesced_area += sf.extent;
coalesced_area += sf.area;
strategy->coalesced_as_needed++;
} else {
strategy->dropped_as_needed++;
@@ -2161,7 +2084,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
bool reduced = false;
if (sf.t == VT_POLYGON) {
if (!prevent[P_TINY_POLYGON_REDUCTION] && !additional[A_GRID_LOW_ZOOMS]) {
sf.geometry = reduce_tiny_poly(sf.geometry, z, line_detail, &reduced, &accum_area);
sf.geometry = reduce_tiny_poly(sf.geometry, z, line_detail, &reduced, &accum_area, &sf, &tiny_feature);
if (reduced) {
strategy->tiny_polygons++;
}
@@ -2214,7 +2137,8 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
p.has_id = sf.has_id;
p.index = sf.index;
p.renamed = -1;
p.extent = sf.extent;
p.area = sf.area;
p.prominence = sf.prominence;
p.clustered = 0;
if (line_detail == detail && extra_detail >= 0 && z == maxzoom) {
@@ -2383,7 +2307,8 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
c.spacing = partials[i].spacing;
c.id = partials[i].id;
c.has_id = partials[i].has_id;
c.extent = partials[i].extent;
c.area = partials[i].area;
c.prominence = partials[i].prominence;
// printf("segment %d layer %lld is %s\n", partials[i].segment, partials[i].layer, (*layer_unmaps)[partials[i].segment][partials[i].layer].c_str());
@@ -2619,16 +2544,16 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
line_detail++;
continue;
} else if (additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED]) {
minextent_fraction = minextent_fraction * max_tile_features / totalsize * 0.75;
long long m = choose_minextent(extents, minextent_fraction);
if (m != minextent) {
minextent = m;
if (minextent > arg->minextent_out) {
arg->minextent_out = minextent;
minarea_fraction = minarea_fraction * max_tile_features / totalsize * 0.75;
long long m = choose_minarea(areas, minarea_fraction);
if (m != minarea) {
minarea = m;
if (minarea > arg->minarea_out) {
arg->minarea_out = minarea;
arg->still_dropping = true;
}
if (!quiet) {
fprintf(stderr, "Going to try keeping the biggest %0.2f%% of the features to make it fit\n", minextent_fraction * 100.0);
fprintf(stderr, "Going to try keeping the biggest %0.2f%% of the features to make it fit\n", minarea_fraction * 100.0);
}
line_detail++;
continue;
@@ -2731,16 +2656,16 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
}
line_detail++;
} else if (additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED]) {
minextent_fraction = minextent_fraction * max_tile_size / (kept_adjust * compressed.size()) * 0.75;
long long m = choose_minextent(extents, minextent_fraction);
if (m != minextent) {
minextent = m;
if (minextent > arg->minextent_out) {
arg->minextent_out = minextent;
minarea_fraction = minarea_fraction * max_tile_size / (kept_adjust * compressed.size()) * 0.75;
long long m = choose_minarea(areas, minarea_fraction);
if (m != minarea) {
minarea = m;
if (minarea > arg->minarea_out) {
arg->minarea_out = minarea;
arg->still_dropping = true;
}
if (!quiet) {
fprintf(stderr, "Going to try keeping the biggest %0.2f%% of the features to make it fit\n", minextent_fraction * 100.0);
fprintf(stderr, "Going to try keeping the biggest %0.2f%% of the features to make it fit\n", minarea_fraction * 100.0);
}
line_detail++;
continue;
@@ -2838,7 +2763,7 @@ void *run_thread(void *vargs) {
// fprintf(stderr, "%d/%u/%u\n", z, x, y);
long long len = write_tile(geom, &geompos, arg->metabase, arg->stringpool, z, x, y, z == arg->maxzoom ? arg->full_detail : arg->low_detail, arg->min_detail, arg->outdb, arg->outdir, arg->buffer, arg->fname, arg->geomfile, arg->minzoom, arg->maxzoom, arg->todo, arg->along, geompos, arg->gamma, arg->child_shards, arg->meta_off, arg->pool_off, arg->initial_x, arg->initial_y, arg->running, arg->simplification, arg->layermaps, arg->layer_unmaps, arg->tiling_seg, arg->pass, arg->passes, arg->mingap, arg->minextent, arg->fraction, arg->prefilter, arg->postfilter, arg->filter, arg, arg->strategy);
long long len = write_tile(geom, &geompos, arg->metabase, arg->stringpool, z, x, y, z == arg->maxzoom ? arg->full_detail : arg->low_detail, arg->min_detail, arg->outdb, arg->outdir, arg->buffer, arg->fname, arg->geomfile, arg->minzoom, arg->maxzoom, arg->todo, arg->along, geompos, arg->gamma, arg->child_shards, arg->meta_off, arg->pool_off, arg->initial_x, arg->initial_y, arg->running, arg->simplification, arg->layermaps, arg->layer_unmaps, arg->tiling_seg, arg->pass, arg->passes, arg->mingap, arg->minarea, arg->fraction, arg->prefilter, arg->postfilter, arg->filter, arg, arg->strategy);
if (len < 0) {
int *err = &arg->err;
@@ -3041,7 +2966,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
double zoom_gamma = gamma;
unsigned long long zoom_mingap = ((1LL << (32 - i)) / 256 * cluster_distance) * ((1LL << (32 - i)) / 256 * cluster_distance);
long long zoom_minextent = 0;
long long zoom_minarea = 0;
double zoom_fraction = 1;
size_t zoom_tile_size = 0;
@@ -3068,8 +2993,8 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
args[thread].gamma_out = zoom_gamma;
args[thread].mingap = zoom_mingap;
args[thread].mingap_out = zoom_mingap;
args[thread].minextent = zoom_minextent;
args[thread].minextent_out = zoom_minextent;
args[thread].minarea = zoom_minarea;
args[thread].minarea_out = zoom_minarea;
args[thread].fraction = zoom_fraction;
args[thread].fraction_out = zoom_fraction;
args[thread].tile_size_out = 0;
@@ -3133,8 +3058,8 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
if (args[thread].mingap_out > zoom_mingap) {
zoom_mingap = args[thread].mingap_out;
}
if (args[thread].minextent_out > zoom_minextent) {
zoom_minextent = args[thread].minextent_out;
if (args[thread].minarea_out > zoom_minarea) {
zoom_minarea = args[thread].minarea_out;
}
if (args[thread].fraction_out < zoom_fraction) {
zoom_fraction = args[thread].fraction_out;
+14 -10
View File
@@ -258,7 +258,7 @@ void write_coords(json_writer &state, lonlat const &ll, double scale) {
}
}
void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale) {
void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long area, long long prominence, bool complain, json_writer &state, double scale) {
for (size_t f = 0; f < layer.features.size(); f++) {
mvt_feature const &feat = layer.features[f];
@@ -271,7 +271,7 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y
state.json_write_unsigned(feat.id);
}
if (name || zoom || index != 0 || sequence != 0 || extent != 0) {
if (name || zoom || index != 0 || sequence != 0 || area != 0 || prominence != 0) {
state.json_write_string("tippecanoe");
state.json_write_hash();
@@ -303,9 +303,13 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y
state.json_write_signed(sequence);
}
if (extent != 0) {
state.json_write_string("extent");
state.json_write_signed(extent);
if (area != 0) {
state.json_write_string("extent"); // keep misleading terminology for compatibility
state.json_write_signed(area);
}
if (prominence != 0) {
state.json_write_string("prominence");
state.json_write_signed(prominence);
}
state.json_end_hash();
@@ -505,16 +509,16 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y
int outer = 0;
for (size_t i = 0; i < rings.size(); i++) {
double area = 0;
double poly_area = 0;
for (size_t k = 0; k < rings[i].size(); k++) {
if (rings[i][k].op != VT_CLOSEPATH) {
area += (double) rings[i][k].x * (double) rings[i][(k + 1) % rings[i].size()].y;
area -= (double) rings[i][k].y * (double) rings[i][(k + 1) % rings[i].size()].x;
poly_area += (double) rings[i][k].x * (double) rings[i][(k + 1) % rings[i].size()].y;
poly_area -= (double) rings[i][k].y * (double) rings[i][(k + 1) % rings[i].size()].x;
}
}
area /= 2;
poly_area /= 2;
areas[i] = area;
areas[i] = poly_area;
if (areas[i] >= 0 || i == 0) {
outer++;
}
+1 -1
View File
@@ -60,7 +60,7 @@ struct json_writer {
void adds(std::string const &s);
};
void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale);
void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long area, long long prominence, bool complain, json_writer &state, double scale);
void fprintq(FILE *f, const char *s);
#endif