mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-02 01:08:14 +00:00
Still not quite a round trip from GeoJSON to GeoJSON, but getting closer
This commit is contained in:
parent
0b47471777
commit
8c5681a582
74
decode.cc
74
decode.cc
@ -173,7 +173,7 @@ void handle(std::string message, int z, unsigned x, unsigned y) {
|
|||||||
ops.push_back(draw(op, lon, lat));
|
ops.push_back(draw(op, lon, lat));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ops.push_back(draw(op, 0, 27));
|
ops.push_back(draw(op, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +227,79 @@ void handle(std::string message, int z, unsigned x, unsigned y) {
|
|||||||
printf(" ] ]");
|
printf(" ] ]");
|
||||||
}
|
}
|
||||||
} else if (feat.type() == VT_POLYGON) {
|
} else if (feat.type() == VT_POLYGON) {
|
||||||
|
std::vector<std::vector<draw> > rings;
|
||||||
|
std::vector<double> areas;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < ops.size(); i++) {
|
||||||
|
if (ops[i].op == VT_MOVETO) {
|
||||||
|
rings.push_back(std::vector<draw>());
|
||||||
|
areas.push_back(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int n = rings.size() - 1;
|
||||||
|
if (n >= 0) {
|
||||||
|
rings[n].push_back(ops[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int outer = 0;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < rings.size(); i++) {
|
||||||
|
double area = 0;
|
||||||
|
for (unsigned k = 0; k < rings[i].size(); k++) {
|
||||||
|
if (rings[i][k].op != VT_CLOSEPATH) {
|
||||||
|
area += rings[i][k].lon * rings[i][(k + 1) % rings[i].size()].lat;
|
||||||
|
area -= rings[i][k].lat * rings[i][(k + 1) % rings[i].size()].lon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
areas[i] = area;
|
||||||
|
if (areas[i] <= 0) {
|
||||||
|
outer++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// printf("area %f\n", area / .00000274 / .00000274);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outer > 1) {
|
||||||
|
printf("\"type\": \"MultiPolygon\", \"coordinates\": [ [ [ ");
|
||||||
|
} else {
|
||||||
|
printf("\"type\": \"Polygon\", \"coordinates\": [ [ ");
|
||||||
|
}
|
||||||
|
|
||||||
|
int state = 0;
|
||||||
|
for (unsigned i = 0; i < rings.size(); i++) {
|
||||||
|
if (areas[i] <= 0) {
|
||||||
|
if (state != 0) {
|
||||||
|
// new multipolygon
|
||||||
|
printf(" ] ], [ [ ");
|
||||||
|
}
|
||||||
|
state = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == 2) {
|
||||||
|
// new ring in the same polygon
|
||||||
|
printf(" ], [ ");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned j = 0; j < rings[i].size(); j++) {
|
||||||
|
if (rings[i][j].op != VT_CLOSEPATH) {
|
||||||
|
if (j != 0) {
|
||||||
|
printf(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("[ %f, %f ]", rings[i][j].lon, rings[i][j].lat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outer > 1) {
|
||||||
|
printf(" ] ] ]");
|
||||||
|
} else {
|
||||||
|
printf(" ] ]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" } }\n");
|
printf(" } }\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user