Enforce polygon winding and closure rules in tippecanoe-decode

This commit is contained in:
Eric Fischer 2017-05-05 10:56:50 -07:00
parent eab593fea5
commit 9eb3a7f7ec
5 changed files with 30 additions and 2 deletions

View File

@ -1,3 +1,7 @@
## 1.17.7
* Enforce polygon winding and closure rules in tippecanoe-decode
## 1.17.6 ## 1.17.6
* Add tile-join options to set name, attribution, description * Add tile-join options to set name, attribution, description

View File

@ -482,3 +482,4 @@ resolutions.
* `-z` _maxzoom_: Specify the highest zoom level to decode from the tileset * `-z` _maxzoom_: Specify the highest zoom level to decode from the tileset
* `-Z` _minzoom_: Specify the lowest zoom level to decode from the tileset * `-Z` _minzoom_: Specify the lowest zoom level to decode from the tileset
* `-l` _layer_: Decode only layers with the specified names. (Multiple `-l` options can be specified.) * `-l` _layer_: Decode only layers with the specified names. (Multiple `-l` options can be specified.)
* `-f`: Decode tiles even if polygon ring order or closure problems are detected

View File

@ -19,6 +19,7 @@
int minzoom = 0; int minzoom = 0;
int maxzoom = 32; int maxzoom = 32;
bool force = false;
void printq(const char *s) { void printq(const char *s) {
putchar('"'); putchar('"');
@ -261,6 +262,15 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe, st
rings[n].push_back(ops[i]); rings[n].push_back(ops[i]);
} }
} }
if (i >= ops.size() || ops[i + 1].op == VT_MOVETO) {
if (ops[i].op != VT_CLOSEPATH) {
fprintf(stderr, "Ring does not end with closepath (ends with %d)\n", ops[i].op);
if (!force) {
exit(EXIT_FAILURE);
}
}
}
} }
int outer = 0; int outer = 0;
@ -290,6 +300,13 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe, st
int state = 0; int state = 0;
for (size_t i = 0; i < rings.size(); i++) { for (size_t i = 0; i < rings.size(); i++) {
if (i == 0 && areas[i] < 0) {
fprintf(stderr, "Polygon begins with an inner ring\n");
if (!force) {
exit(EXIT_FAILURE);
}
}
if (areas[i] >= 0) { if (areas[i] >= 0) {
if (state != 0) { if (state != 0) {
// new multipolygon // new multipolygon
@ -489,7 +506,7 @@ int main(int argc, char **argv) {
int i; int i;
std::set<std::string> to_decode; std::set<std::string> to_decode;
while ((i = getopt(argc, argv, "t:Z:z:l:")) != -1) { while ((i = getopt(argc, argv, "t:Z:z:l:f")) != -1) {
switch (i) { switch (i) {
case 't': case 't':
set_projection_or_exit(optarg); set_projection_or_exit(optarg);
@ -507,6 +524,10 @@ int main(int argc, char **argv) {
to_decode.insert(optarg); to_decode.insert(optarg);
break; break;
case 'f':
force = true;
break;
default: default:
usage(argv); usage(argv);
} }

View File

@ -568,4 +568,6 @@ resolutions.
\fB\fC\-Z\fR \fIminzoom\fP: Specify the lowest zoom level to decode from the tileset \fB\fC\-Z\fR \fIminzoom\fP: Specify the lowest zoom level to decode from the tileset
.IP \(bu 2 .IP \(bu 2
\fB\fC\-l\fR \fIlayer\fP: Decode only layers with the specified names. (Multiple \fB\fC\-l\fR options can be specified.) \fB\fC\-l\fR \fIlayer\fP: Decode only layers with the specified names. (Multiple \fB\fC\-l\fR options can be specified.)
.IP \(bu 2
\fB\fC\-f\fR: Decode tiles even if polygon ring order or closure problems are detected
.RE .RE

View File

@ -1 +1 @@
#define VERSION "tippecanoe v1.17.6\n" #define VERSION "tippecanoe v1.17.7\n"