mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-03-26 05:37:38 +00:00
Merge pull request #105 from mapbox/polygon-close
Use closepath for each polygon ring to match the vector tile spec
This commit is contained in:
commit
0ff0bf1ad9
@ -295,6 +295,12 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
||||
}
|
||||
|
||||
printf("[ %f, %f ]", rings[i][j].lon, rings[i][j].lat);
|
||||
} else {
|
||||
if (j != 0) {
|
||||
printf(", ");
|
||||
}
|
||||
|
||||
printf("[ %f, %f ]", rings[i][0].lon, rings[i][0].lat);
|
||||
}
|
||||
}
|
||||
|
||||
|
31
geometry.cc
31
geometry.cc
@ -98,7 +98,6 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
|
||||
}
|
||||
|
||||
if (geom[i].op == VT_CLOSEPATH) {
|
||||
fprintf(stderr, "Shouldn't happen\n");
|
||||
out.push_back(geom[i]);
|
||||
} else { /* moveto or lineto */
|
||||
out.push_back(geom[i]);
|
||||
@ -310,6 +309,36 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool cl
|
||||
return out;
|
||||
}
|
||||
|
||||
drawvec close_poly(drawvec &geom) {
|
||||
drawvec out;
|
||||
|
||||
for (unsigned i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
unsigned j;
|
||||
for (j = i + 1; j < geom.size(); j++) {
|
||||
if (geom[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j - 1 > i) {
|
||||
if (geom[j - 1].x != geom[i].x || geom[j - 1].y != geom[i].y) {
|
||||
fprintf(stderr, "Internal error: polygon not closed\n");
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned n = i; n < j - 1; n++) {
|
||||
out.push_back(geom[n]);
|
||||
}
|
||||
out.push_back(draw(VT_CLOSEPATH, 0, 0));
|
||||
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area) {
|
||||
drawvec out;
|
||||
long long pixel = (1 << (32 - detail - z)) * 2;
|
||||
|
@ -21,6 +21,7 @@ void to_tile_scale(drawvec &geom, int z, int detail);
|
||||
drawvec remove_noop(drawvec geom, int type, int shift);
|
||||
drawvec clip_point(drawvec &geom, int z, int detail, long long buffer);
|
||||
drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool clip);
|
||||
drawvec close_poly(drawvec &geom);
|
||||
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area);
|
||||
drawvec clip_lines(drawvec &geom, int z, int detail, long long buffer);
|
||||
int quick_check(long long *bbox, int z, int detail, long long buffer);
|
||||
|
1
tile.cc
1
tile.cc
@ -656,6 +656,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
||||
// Scaling may have made the polygon degenerate.
|
||||
// Give Clipper a chance to try to fix it.
|
||||
geom = clean_or_clip_poly(geom, 0, 0, 0, false);
|
||||
geom = close_poly(geom);
|
||||
}
|
||||
|
||||
if (t == VT_POINT || to_feature(geom, NULL)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user