Fix area calculation for polygon rings in tippecanoe-decode

This commit is contained in:
Eric Fischer 2016-05-10 12:13:03 -07:00
parent 4f01b13fe1
commit 24327e195f
10 changed files with 780 additions and 772 deletions

View File

@ -33,11 +33,15 @@ struct lonlat {
int op;
double lon;
double lat;
int x;
int y;
lonlat(int nop, double nlon, double nlat) {
lonlat(int nop, double nlon, double nlat, int nx, int ny) {
this->op = nop;
this->lon = nlon;
this->lat = nlat;
this->x = nx;
this->y = ny;
}
};
@ -156,9 +160,9 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
double lat, lon;
tile2latlon(wx, wy, 32, &lat, &lon);
ops.push_back(lonlat(op, lon, lat));
ops.push_back(lonlat(op, lon, lat, px, py));
} else {
ops.push_back(lonlat(op, 0, 0));
ops.push_back(lonlat(op, 0, 0, 0, 0));
}
}
@ -223,23 +227,27 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
int n = rings.size() - 1;
if (n >= 0) {
rings[n].push_back(ops[i]);
if (ops[i].op == VT_CLOSEPATH) {
rings[n].push_back(rings[n][0]);
} else {
rings[n].push_back(ops[i]);
}
}
}
int outer = 0;
for (size_t i = 0; i < rings.size(); i++) {
double area = 0;
long double area = 0;
for (size_t 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;
area += rings[i][k].x * rings[i][(k + 1) % rings[i].size()].y;
area -= rings[i][k].y * rings[i][(k + 1) % rings[i].size()].x;
}
}
areas[i] = area;
if (areas[i] <= 0 || i == 0) {
if (areas[i] >= 0 || i == 0) {
outer++;
}
@ -254,7 +262,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
int state = 0;
for (size_t i = 0; i < rings.size(); i++) {
if (areas[i] <= 0) {
if (areas[i] >= 0) {
if (state != 0) {
// new multipolygon
printf(" ] ], [ [ ");

View File

@ -12,7 +12,7 @@
}, "features": [
{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in" }, "features": [
{ "type": "Feature", "properties": { "boolean": true, "otherboolean": false, "stringify": "[\"yes\",27.00000000,27,1.4e27,{\"foo\":\"bar\"}]", "escape": "foo\u0001bar,ü\"\\/\u0008\u000c\u000a\u000d\u0009→", "prêt": "ready" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -177.539062, 44.339565 ], [ -164.882812, 43.389082 ], [ -153.281250, 46.619261 ], [ -144.492188, 51.179343 ], [ -143.789062, 57.183902 ], [ -148.007812, 61.100789 ], [ -158.554688, 63.860036 ], [ -169.453125, 64.510643 ], [ -177.890625, 62.593341 ], [ -180.000000, 61.689872 ], [ -185.976562, 58.859224 ], [ -187.031250, 56.992883 ], [ -187.031250, 65.730626 ], [ -182.460938, 67.339861 ], [ -180.000000, 67.542167 ], [ -169.101562, 68.269387 ], [ -156.093750, 68.138852 ], [ -144.492188, 66.089364 ], [ -134.648438, 62.431074 ], [ -131.835938, 55.379110 ], [ -133.593750, 48.690960 ], [ -146.250000, 38.616870 ], [ -169.453125, 34.957995 ], [ -180.000000, 36.527295 ], [ -184.218750, 37.160317 ], [ -187.031250, 38.891033 ], [ -187.031250, 50.457504 ], [ -185.976562, 47.279229 ], [ -177.539062, 44.339565 ] ], [ [ 187.031250, 35.460670 ], [ 175.781250, 37.160317 ], [ 161.718750, 45.336702 ], [ 156.796875, 55.028022 ], [ 163.476562, 62.431074 ], [ 170.507812, 64.811557 ], [ 177.539062, 67.339861 ], [ 180.000000, 67.542167 ], [ 187.031250, 68.007571 ], [ 187.031250, 63.743631 ], [ 182.109375, 62.593341 ], [ 180.000000, 61.689872 ], [ 174.023438, 58.859224 ], [ 171.562500, 54.418930 ], [ 174.023438, 47.279229 ], [ 182.460938, 44.339565 ], [ 187.031250, 44.024422 ], [ 187.031250, 35.460670 ] ] ] } }
{ "type": "Feature", "properties": { "boolean": true, "otherboolean": false, "stringify": "[\"yes\",27.00000000,27,1.4e27,{\"foo\":\"bar\"}]", "escape": "foo\u0001bar,ü\"\\/\u0008\u000c\u000a\u000d\u0009→", "prêt": "ready" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -177.539062, 44.339565 ], [ -164.882812, 43.389082 ], [ -153.281250, 46.619261 ], [ -144.492188, 51.179343 ], [ -143.789062, 57.183902 ], [ -148.007812, 61.100789 ], [ -158.554688, 63.860036 ], [ -169.453125, 64.510643 ], [ -177.890625, 62.593341 ], [ -180.000000, 61.689872 ], [ -185.976562, 58.859224 ], [ -187.031250, 56.992883 ], [ -187.031250, 65.730626 ], [ -182.460938, 67.339861 ], [ -180.000000, 67.542167 ], [ -169.101562, 68.269387 ], [ -156.093750, 68.138852 ], [ -144.492188, 66.089364 ], [ -134.648438, 62.431074 ], [ -131.835938, 55.379110 ], [ -133.593750, 48.690960 ], [ -146.250000, 38.616870 ], [ -169.453125, 34.957995 ], [ -180.000000, 36.527295 ], [ -184.218750, 37.160317 ], [ -187.031250, 38.891033 ], [ -187.031250, 50.457504 ], [ -185.976562, 47.279229 ], [ -177.539062, 44.339565 ] ] ], [ [ [ 187.031250, 35.460670 ], [ 175.781250, 37.160317 ], [ 161.718750, 45.336702 ], [ 156.796875, 55.028022 ], [ 163.476562, 62.431074 ], [ 170.507812, 64.811557 ], [ 177.539062, 67.339861 ], [ 180.000000, 67.542167 ], [ 187.031250, 68.007571 ], [ 187.031250, 63.743631 ], [ 182.109375, 62.593341 ], [ 180.000000, 61.689872 ], [ 174.023438, 58.859224 ], [ 171.562500, 54.418930 ], [ 174.023438, 47.279229 ], [ 182.460938, 44.339565 ], [ 187.031250, 44.024422 ], [ 187.031250, 35.460670 ] ] ] ] } }
,
{ "type": "Feature", "properties": { "zoom": "z0-2" }, "geometry": { "type": "LineString", "coordinates": [ [ -112.851562, 55.178868 ], [ -117.773438, 44.590467 ], [ -104.414062, 51.179343 ] ] } }
] }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long