mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-03-23 04:15:15 +00:00
Split complex polygons into multiple features
This commit is contained in:
parent
ca4faec9f6
commit
ea304d3a98
@ -114,6 +114,7 @@ Options
|
||||
* -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.
|
||||
* -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).
|
||||
* -pp: Don't split complex polygons (over 700 vertices after simplification) into multiple features.
|
||||
* -q: Work quietly instead of reporting progress
|
||||
|
||||
Example
|
||||
@ -202,6 +203,9 @@ have their probability diffused, so that some of them will be drawn as a square
|
||||
this minimum size and others will not be drawn at all, preserving the total area that
|
||||
all of them should have had together.
|
||||
|
||||
Any polygons that have over 700 vertices after line simplification will be split into
|
||||
multiple features so they can be rendered efficiently, unless you use -pp to prevent this.
|
||||
|
||||
Features in the same tile that share the same type and attributes are coalesced
|
||||
together into a single geometry. You are strongly encouraged to use -x to exclude
|
||||
any unnecessary properties to reduce wasted file size.
|
||||
|
25
geometry.cc
25
geometry.cc
@ -436,7 +436,9 @@ static drawvec clip_poly1(drawvec &geom, long long minx, long long miny, long lo
|
||||
}
|
||||
|
||||
if (out.size() < 3) {
|
||||
fprintf(stderr, "Polygon degenerated to a line segment\n");
|
||||
// fprintf(stderr, "Polygon degenerated to a line segment\n");
|
||||
out.clear();
|
||||
return out;
|
||||
}
|
||||
|
||||
out[0].op = VT_MOVETO;
|
||||
@ -943,16 +945,12 @@ drawvec fix_polygon(drawvec &geom) {
|
||||
}
|
||||
|
||||
std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms) {
|
||||
return geoms;
|
||||
|
||||
while (1) {
|
||||
bool again = false;
|
||||
std::vector<drawvec> out;
|
||||
|
||||
for (unsigned i = 0; i < geoms.size(); i++) {
|
||||
if (geoms[i].size() > 700) {
|
||||
again = true;
|
||||
|
||||
long long midx = 0, midy = 0, count = 0;
|
||||
long long maxx = LONG_LONG_MIN, maxy = LONG_LONG_MIN, minx = LONG_LONG_MAX, miny = LONG_LONG_MAX;
|
||||
|
||||
@ -976,6 +974,23 @@ std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
midx /= count;
|
||||
midy /= count;
|
||||
|
||||
if (maxy - miny > maxx - minx) {
|
||||
// printf("clipping y to %lld %lld %lld %lld\n", minx, miny, maxx, midy);
|
||||
out.push_back(simple_clip_poly(geoms[i], minx, miny, maxx, midy));
|
||||
// printf(" and %lld %lld %lld %lld\n", minx, midy, maxx, maxy);
|
||||
out.push_back(simple_clip_poly(geoms[i], minx, midy, maxx, maxy));
|
||||
} else {
|
||||
// printf("clipping x to %lld %lld %lld %lld\n", minx, miny, midx, maxy);
|
||||
out.push_back(simple_clip_poly(geoms[i], minx, miny, midx, maxy));
|
||||
// printf(" and %lld %lld %lld %lld\n", midx, midy, maxx, maxy);
|
||||
out.push_back(simple_clip_poly(geoms[i], midx, miny, maxx, maxy));
|
||||
}
|
||||
|
||||
again = true;
|
||||
} else {
|
||||
out.push_back(geoms[i]);
|
||||
}
|
||||
|
@ -29,3 +29,4 @@ int quick_check(long long *bbox, int z, int detail, long long buffer);
|
||||
drawvec simplify_lines(drawvec &geom, int z, int detail);
|
||||
drawvec reorder_lines(drawvec &geom);
|
||||
drawvec fix_polygon(drawvec &geom);
|
||||
std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms);
|
||||
|
@ -8,6 +8,8 @@ features. This is a tool for making maps from huge datasets
|
||||
.PP
|
||||
[Build Status](https://travis\-ci.org/mapbox/tippecanoe.svg)
|
||||
\[la]https://travis-ci.org/mapbox/tippecanoe\[ra]
|
||||
[Coverage Status](https://coveralls.io/repos/mapbox/tippecanoe/badge.svg?branch=master&service=github)
|
||||
\[la]https://coveralls.io/github/mapbox/tippecanoe?branch=master\[ra]
|
||||
.SH Intent
|
||||
.PP
|
||||
The goal of Tippecanoe is to enable making a scale\-independent view of your data,
|
||||
@ -143,6 +145,8 @@ If you use \-rg, it will guess a drop rate that will keep at most 50,000 feature
|
||||
.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
|
||||
\-pp: Don't split complex polygons (over 700 vertices after simplification) into multiple features.
|
||||
.IP \(bu 2
|
||||
\-q: Work quietly instead of reporting progress
|
||||
.RE
|
||||
.SH Example
|
||||
@ -232,6 +236,9 @@ have their probability diffused, so that some of them will be drawn as a square
|
||||
this minimum size and others will not be drawn at all, preserving the total area that
|
||||
all of them should have had together.
|
||||
.PP
|
||||
Any polygons that have over 700 vertices after line simplification will be split into
|
||||
multiple features so they can be rendered efficiently, unless you use \-pp to prevent this.
|
||||
.PP
|
||||
Features in the same tile that share the same type and attributes are coalesced
|
||||
together into a single geometry. You are strongly encouraged to use \-x to exclude
|
||||
any unnecessary properties to reduce wasted file size.
|
||||
|
118
tests/tl_2015_us_county/out/-z8.json
Normal file
118
tests/tl_2015_us_county/out/-z8.json
Normal file
File diff suppressed because one or more lines are too long
114
tests/tl_2015_us_county/out/-z8_-pp.json
Normal file
114
tests/tl_2015_us_county/out/-z8_-pp.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/tl_2015_us_county/somerset.json
Normal file
1
tests/tl_2015_us_county/somerset.json
Normal file
File diff suppressed because one or more lines are too long
6
tile.cc
6
tile.cc
@ -529,11 +529,9 @@ void *partial_feature_worker(void *v) {
|
||||
std::vector<drawvec> geoms;
|
||||
geoms.push_back(geom);
|
||||
|
||||
#if 0
|
||||
if (t == VT_POLYGON) {
|
||||
geoms = chop_geometry(geoms); // XXX
|
||||
if (t == VT_POLYGON && !prevent[P_POLYGON_SPLIT]) {
|
||||
geoms = chop_polygon(geoms);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (t == VT_POLYGON) {
|
||||
// Scaling may have made the polygon degenerate.
|
||||
|
Loading…
x
Reference in New Issue
Block a user