mirror of
https://github.com/felt/tippecanoe.git
synced 2026-11-28 03:11:18 +01:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b03b18f31 | ||
|
|
b763625862 |
@@ -1,7 +1,12 @@
|
||||
## 2.9.1
|
||||
|
||||
* Do label generation after simplification, not before.
|
||||
|
||||
## 2.9.0
|
||||
|
||||
* 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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
+202
-83
@@ -92,6 +92,17 @@ void to_tile_scale(drawvec &geom, int z, int detail) {
|
||||
}
|
||||
}
|
||||
|
||||
drawvec from_tile_scale(drawvec const &geom, int z, int detail) {
|
||||
drawvec out;
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
draw d = geom[i];
|
||||
d.x <<= (32 - detail - z);
|
||||
d.y <<= (32 - detail - z);
|
||||
out.push_back(d);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
drawvec remove_noop(drawvec geom, int type, int shift) {
|
||||
// first pass: remove empty linetos
|
||||
|
||||
@@ -590,9 +601,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 +649,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 +669,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 +687,28 @@ 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 (tiny_feature->extent > this_feature->extent) {
|
||||
*this_feature = *tiny_feature;
|
||||
tiny_feature->extent = 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 (this_feature->extent > tiny_feature->extent) {
|
||||
*tiny_feature = *this_feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1441,15 +1478,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 +1516,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 +1528,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;
|
||||
}
|
||||
|
||||
+4
-1
@@ -56,15 +56,17 @@ 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);
|
||||
drawvec from_tile_scale(drawvec const &geom, int z, int detail);
|
||||
drawvec remove_noop(drawvec geom, int type, int shift);
|
||||
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 +79,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);
|
||||
|
||||
@@ -2427,7 +2427,7 @@ int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzo
|
||||
|
||||
if (maxzoom != written) {
|
||||
if (written > minzoom) {
|
||||
fprintf(stderr, "\n\n\n*** NOTE TILES ONLY COMPLETE THROUGH ZOOM %d ***\n\n\n", written);
|
||||
fprintf(stderr, "\n\n\n*** NOTE TILES ONLY COMPLETE THROUGH ZOOM %d ***\n", written);
|
||||
maxzoom = written;
|
||||
ret = EXIT_INCOMPLETE;
|
||||
} else {
|
||||
|
||||
@@ -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": [
|
||||
|
||||
+258
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -447,9 +447,12 @@ struct partial {
|
||||
long long layer = 0;
|
||||
long long original_seq = 0;
|
||||
unsigned long long index = 0;
|
||||
unsigned long long label_point = 0;
|
||||
int segment = 0;
|
||||
bool reduced = 0;
|
||||
int z = 0;
|
||||
int tx = 0;
|
||||
int ty = 0;
|
||||
int line_detail = 0;
|
||||
int extra_detail = 0;
|
||||
int maxzoom = 0;
|
||||
@@ -575,31 +578,37 @@ void *partial_feature_worker(void *v) {
|
||||
|
||||
to_tile_scale(geom, z, out_detail);
|
||||
|
||||
std::vector<drawvec> geoms;
|
||||
geoms.push_back(geom);
|
||||
|
||||
if (t == VT_POLYGON) {
|
||||
// Scaling may have made the polygon degenerate.
|
||||
// Give Clipper a chance to try to fix it.
|
||||
for (size_t g = 0; g < geoms.size(); g++) {
|
||||
drawvec before = geoms[g];
|
||||
geoms[g] = clean_or_clip_poly(geoms[g], 0, 0, false);
|
||||
{
|
||||
drawvec before = geom;
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false);
|
||||
if (additional[A_DEBUG_POLYGON]) {
|
||||
check_polygon(geoms[g]);
|
||||
check_polygon(geom);
|
||||
}
|
||||
|
||||
if (geoms[g].size() < 3) {
|
||||
if (geom.size() < 3) {
|
||||
if (area > 0) {
|
||||
// area is in world coordinates, calculated before scaling down
|
||||
geoms[g] = revive_polygon(before, area / geoms.size(), z, out_detail);
|
||||
geom = revive_polygon(before, area, z, out_detail);
|
||||
} else {
|
||||
geoms[g].clear();
|
||||
geom.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (t == VT_POLYGON && additional[A_GENERATE_POLYGON_LABEL_POINTS]) {
|
||||
t = (*partials)[i].t = VT_POINT;
|
||||
geom = spiral_anchors(from_tile_scale(geom, z, out_detail), (*partials)[i].tx, (*partials)[i].ty, z, (*partials)[i].label_point);
|
||||
to_tile_scale(geom, z, out_detail);
|
||||
}
|
||||
|
||||
(*partials)[i].index = i;
|
||||
|
||||
std::vector<drawvec> geoms; // artifact of former polygon-splitting to reduce geometric complexity
|
||||
geoms.push_back(geom);
|
||||
(*partials)[i].geoms = geoms;
|
||||
}
|
||||
|
||||
@@ -1801,95 +1810,6 @@ 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) {
|
||||
double merge_fraction = 1;
|
||||
double mingap_fraction = 1;
|
||||
@@ -1973,6 +1893,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;
|
||||
@@ -2161,7 +2083,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++;
|
||||
}
|
||||
@@ -2174,11 +2096,6 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
|
||||
}
|
||||
}
|
||||
|
||||
if (sf.t == VT_POLYGON && additional[A_GENERATE_POLYGON_LABEL_POINTS]) {
|
||||
sf.t = VT_POINT;
|
||||
sf.geometry = spiral_anchors(sf.geometry, tx, ty, z, sf.label_point);
|
||||
}
|
||||
|
||||
if (sf.geometry.size() > 0) {
|
||||
if (partials.size() > max_tile_size) {
|
||||
// Even being maximally conservative, each feature is still going to be
|
||||
@@ -2201,6 +2118,8 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
|
||||
p.original_seq = sf.seq;
|
||||
p.reduced = reduced;
|
||||
p.z = z;
|
||||
p.tx = tx;
|
||||
p.ty = ty;
|
||||
p.line_detail = line_detail;
|
||||
p.extra_detail = line_detail;
|
||||
p.maxzoom = maxzoom;
|
||||
@@ -2213,6 +2132,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
|
||||
p.id = sf.id;
|
||||
p.has_id = sf.has_id;
|
||||
p.index = sf.index;
|
||||
p.label_point = sf.label_point;
|
||||
p.renamed = -1;
|
||||
p.extent = sf.extent;
|
||||
p.clustered = 0;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef VERSION_HPP
|
||||
#define VERSION_HPP
|
||||
|
||||
#define VERSION "v2.9.0"
|
||||
#define VERSION "v2.9.1"
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user