mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 16:35:40 +02:00
Switch other calls to Wagyu over. But now coalesce is slow.
This commit is contained in:
@@ -67,7 +67,7 @@ tippecanoe-enumerate: enumerate.o
|
||||
tippecanoe-decode: decode.o projection.o mvt.o write_json.o text.o jsonpull/jsonpull.o dirtiles.o pmtiles_file.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3
|
||||
|
||||
tile-join: tile-join.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o
|
||||
tile-join: tile-join.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o polygon.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o
|
||||
@@ -76,7 +76,7 @@ tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o
|
||||
unit: unit.o text.o sort.o mvt.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
tippecanoe-overzoom: overzoom.o mvt.o clip.o
|
||||
tippecanoe-overzoom: overzoom.o mvt.o clip.o polygon.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
-include $(wildcard *.d)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "errors.hpp"
|
||||
#include "compression.hpp"
|
||||
#include "mvt.hpp"
|
||||
#include "polygon.hpp"
|
||||
|
||||
static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<double, double>> &geom,
|
||||
long long minx, long long miny, long long maxx, long long maxy,
|
||||
@@ -852,13 +853,17 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int
|
||||
|
||||
// Scale to output tile extent
|
||||
|
||||
to_tile_scale(geom, nz, det);
|
||||
if (t == VT_POLYGON) {
|
||||
geom = scale_polygon(geom, nz, det);
|
||||
} else {
|
||||
to_tile_scale(geom, nz, det);
|
||||
}
|
||||
|
||||
// Clean geometries
|
||||
|
||||
geom = remove_noop(geom, t, 0);
|
||||
if (t == VT_POLYGON) {
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false, false);
|
||||
geom = clean_polygon(geom, 1LL << det);
|
||||
geom = close_poly(geom);
|
||||
}
|
||||
|
||||
@@ -929,3 +934,25 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/* pnpoly:
|
||||
Copyright (c) 1970-2003, Wm. Randolph Franklin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
|
||||
Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution.
|
||||
The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy) {
|
||||
size_t i, j;
|
||||
bool c = false;
|
||||
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
|
||||
if (((vert[i + start].y > testy) != (vert[j + start].y > testy)) &&
|
||||
(testx < (vert[j + start].x - vert[i + start].x) * (testy - vert[i + start].y) / (double) (vert[j + start].y - vert[i + start].y) + vert[i + start].x))
|
||||
c = !c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -79,28 +79,6 @@ drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, long long
|
||||
return out;
|
||||
}
|
||||
|
||||
/* pnpoly:
|
||||
Copyright (c) 1970-2003, Wm. Randolph Franklin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
|
||||
Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution.
|
||||
The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy) {
|
||||
size_t i, j;
|
||||
bool c = false;
|
||||
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
|
||||
if (((vert[i + start].y > testy) != (vert[j + start].y > testy)) &&
|
||||
(testx < (vert[j + start].x - vert[i + start].x) * (testy - vert[i + start].y) / (double) (vert[j + start].y - vert[i + start].y) + vert[i + start].x))
|
||||
c = !c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void check_polygon(drawvec &geom) {
|
||||
geom = remove_noop(geom, VT_POLYGON, 0);
|
||||
|
||||
|
||||
+12
-5
@@ -25,6 +25,7 @@
|
||||
#include "geometry.hpp"
|
||||
#include "serial.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "polygon.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include "jsonpull/jsonpull.h"
|
||||
@@ -194,16 +195,22 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
|
||||
dv = fix_polygon(dv);
|
||||
}
|
||||
|
||||
// Scale and offset geometry from global to tile
|
||||
// Offset geometry from global to tile
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
long long scale = 1LL << (32 - z);
|
||||
dv[i].x = std::round((dv[i].x - scale * x) * extent / (double) scale);
|
||||
dv[i].y = std::round((dv[i].y - scale * y) * extent / (double) scale);
|
||||
dv[i].x = dv[i].x - scale * x;
|
||||
dv[i].y = dv[i].y - scale * y;
|
||||
}
|
||||
// Scale to tile extent
|
||||
int detail = std::round(log(extent) / log(2));
|
||||
if (t == VT_POLYGON) {
|
||||
dv = scale_polygon(dv, z, detail);
|
||||
} else {
|
||||
to_tile_scale(dv, z, detail);
|
||||
}
|
||||
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
// we can try scaling up because these are tile coordinates
|
||||
dv = clean_or_clip_poly(dv, 0, 0, false, true);
|
||||
dv = clean_polygon(dv, extent); // tile coordinates
|
||||
if (dv.size() < 3) {
|
||||
dv.clear();
|
||||
}
|
||||
|
||||
+11
-11
@@ -430,6 +430,16 @@ void snap_round(std::vector<segment> &segs, long long extent) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://www.cuemath.com/geometry/area-of-triangle-in-coordinate-geometry/
|
||||
double triangle_area(drawvec const &geom, size_t base, size_t increment, size_t len) {
|
||||
double area = ((double) geom[base + (increment + 0) % len].x * (geom[base + (increment + 1) % len].y - geom[base + (increment + 2) % len].y) +
|
||||
(double) geom[base + (increment + 1) % len].x * (geom[base + (increment + 2) % len].y - geom[base + (increment + 0) % len].y) +
|
||||
(double) geom[base + (increment + 2) % len].x * (geom[base + (increment + 0) % len].y - geom[base + (increment + 1) % len].y)) /
|
||||
2;
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
struct ring_area {
|
||||
drawvec geom;
|
||||
double area;
|
||||
@@ -446,7 +456,7 @@ struct ring_area {
|
||||
long long x = (geom[i].x + geom[i + 1].x + geom[i + 2].x) / 3;
|
||||
long long y = (geom[i].y + geom[i + 1].y + geom[i + 2].y) / 3;
|
||||
|
||||
if (get_area(geom, i, i + 3) != 0 && pnpoly(geom, 0, geom.size(), x, y)) {
|
||||
if (triangle_area(geom, 0, i, geom.size() - 1) != 0 && pnpoly(geom, 0, geom.size(), x, y)) {
|
||||
ear_x = x;
|
||||
ear_y = y;
|
||||
return;
|
||||
@@ -689,16 +699,6 @@ drawvec remove_collinear(drawvec const &geom) {
|
||||
return out;
|
||||
}
|
||||
|
||||
// https://www.cuemath.com/geometry/area-of-triangle-in-coordinate-geometry/
|
||||
double triangle_area(drawvec const &geom, size_t base, size_t increment, size_t len) {
|
||||
double area = ((double) geom[base + (increment + 0) % len].x * (geom[base + (increment + 1) % len].y - geom[base + (increment + 2) % len].y) +
|
||||
(double) geom[base + (increment + 1) % len].x * (geom[base + (increment + 2) % len].y - geom[base + (increment + 0) % len].y) +
|
||||
(double) geom[base + (increment + 2) % len].x * (geom[base + (increment + 0) % len].y - geom[base + (increment + 1) % len].y)) /
|
||||
2;
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
drawvec scale_polygon(drawvec const &geom, int z, int detail) {
|
||||
double scale = 1LL << (32 - detail - z);
|
||||
drawvec out;
|
||||
|
||||
File diff suppressed because one or more lines are too long
+16
-16
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
@@ -14,7 +14,7 @@
|
||||
}, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -32.958984, 79.004962 ], [ -2.988281, 61.015725 ], [ -15.380859, 52.855864 ], [ -10.019531, 50.007739 ], [ -5.009766, 7.972198 ], [ -16.962891, -22.024546 ], [ -74.970703, -30.977609 ], [ -118.037109, -9.015302 ], [ -135.000000, 28.998532 ], [ -113.027344, 53.014783 ], [ -111.884766, 53.435719 ], [ -116.982422, 60.020952 ], [ -113.027344, 69.005675 ], [ -92.988281, 75.004940 ], [ -74.003906, 79.004962 ], [ -32.958984, 79.004962 ] ] ] } }
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -74.003906, 79.004962 ], [ -32.958984, 79.004962 ], [ -2.988281, 61.015725 ], [ -15.380859, 52.855864 ], [ -10.019531, 50.007739 ], [ -5.009766, 7.972198 ], [ -16.962891, -22.024546 ], [ -74.970703, -30.977609 ], [ -118.037109, -9.015302 ], [ -135.000000, 28.998532 ], [ -113.027344, 53.014783 ], [ -111.884766, 53.435719 ], [ -116.982422, 60.020952 ], [ -113.027344, 69.005675 ], [ -92.988281, 75.004940 ], [ -74.003906, 79.004962 ] ] ] } }
|
||||
] }
|
||||
] }
|
||||
] }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{ "type": "FeatureCollection", "properties": { "zoom": 13, "x": 1310, "y": 3166 }, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_land", "version": 2, "extent": 256 }, "features": [
|
||||
{ "type": "Feature", "properties": { "scalerank": 0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.388897, 37.792151 ], [ -122.387867, 37.790930 ], [ -122.387009, 37.778720 ], [ -122.382545, 37.774514 ], [ -122.382545, 37.766101 ], [ -122.382889, 37.763794 ], [ -122.382545, 37.763116 ], [ -122.382545, 37.749272 ], [ -122.436790, 37.749272 ], [ -122.436790, 37.792151 ], [ -122.388897, 37.792151 ] ] ] } }
|
||||
{ "type": "Feature", "properties": { "scalerank": 0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.436790, 37.792151 ], [ -122.388897, 37.792151 ], [ -122.387867, 37.790930 ], [ -122.387009, 37.778720 ], [ -122.382545, 37.774514 ], [ -122.382545, 37.766101 ], [ -122.382889, 37.763794 ], [ -122.382545, 37.763116 ], [ -122.382545, 37.749272 ], [ -122.436790, 37.749272 ], [ -122.436790, 37.792151 ] ] ] } }
|
||||
] }
|
||||
,
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_populated_places", "version": 2, "extent": 256 }, "features": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{ "type": "FeatureCollection", "properties": { "zoom": 13, "x": 1310, "y": 3166 }, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_land", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { "featurecla": "Land", "scalerank": 0, "min_zoom": 0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.387760, 37.788760 ], [ -122.387094, 37.778754 ], [ -122.386837, 37.778517 ], [ -122.386837, 37.752665 ], [ -122.432499, 37.752665 ], [ -122.432499, 37.788760 ], [ -122.387760, 37.788760 ] ] ] } }
|
||||
{ "type": "Feature", "properties": { "featurecla": "Land", "scalerank": 0, "min_zoom": 0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.432499, 37.788760 ], [ -122.387760, 37.788760 ], [ -122.387094, 37.778754 ], [ -122.386837, 37.778517 ], [ -122.386837, 37.752665 ], [ -122.432499, 37.752665 ], [ -122.432499, 37.788760 ] ] ] } }
|
||||
] }
|
||||
,
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_populated_places", "version": 2, "extent": 4096 }, "features": [
|
||||
|
||||
@@ -577,9 +577,7 @@ double simplify_partial(partial *p, drawvec const &shared_nodes, node *shared_no
|
||||
// clean coalesced polygons before simplification to avoid
|
||||
// introducing shards between shapes that otherwise would have
|
||||
// unioned exactly
|
||||
//
|
||||
// don't try to scale up because these are still world coordinates
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false, false);
|
||||
geom = clean_polygon(geom, 1LL << (32 - z)); // world coordinates at zoom z
|
||||
}
|
||||
|
||||
// continues to simplify to line_detail even if we have extra detail
|
||||
@@ -616,7 +614,7 @@ void *partial_feature_worker(void *v) {
|
||||
|
||||
if (t == VT_POLYGON) {
|
||||
geom = scale_polygon(geom, z, out_detail);
|
||||
geom = clean_polygon(geom, 1LL << out_detail);
|
||||
geom = clean_polygon(geom, 1LL << out_detail); // tile coordinates
|
||||
} else {
|
||||
to_tile_scale(geom, z, out_detail);
|
||||
}
|
||||
@@ -1643,7 +1641,7 @@ void *run_prefilter(void *v) {
|
||||
tmp_layer.name = (*(rpa->layer_unmaps))[sf.segment][sf.layer];
|
||||
|
||||
if (sf.t == VT_POLYGON) {
|
||||
sf.geometry = close_poly(sf.geometry);
|
||||
sf.geometry = close_poly(sf.geometry); // i.e., change last lineto to closepath
|
||||
}
|
||||
|
||||
mvt_feature tmp_feature;
|
||||
@@ -2277,8 +2275,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
||||
|
||||
for (auto &g : partials[simplified_geometry_through].geoms) {
|
||||
if (partials[simplified_geometry_through].t == VT_POLYGON) {
|
||||
// don't scale up because this is still world coordinates
|
||||
g = clean_or_clip_poly(g, 0, 0, false, false);
|
||||
g = clean_polygon(g, 1LL << (32 - z)); // world coordinates at zoom z
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2517,11 +2514,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
||||
|
||||
if (layer_features[x].type == VT_POLYGON) {
|
||||
if (layer_features[x].coalesced) {
|
||||
// we can try scaling up because this is tile coordinates
|
||||
layer_features[x].geom = clean_or_clip_poly(layer_features[x].geom, 0, 0, false, true);
|
||||
layer_features[x].geom = clean_polygon(layer_features[x].geom, 1LL << (32 - z)); // world coordinates at zoom z
|
||||
}
|
||||
|
||||
layer_features[x].geom = close_poly(layer_features[x].geom);
|
||||
layer_features[x].geom = close_poly(layer_features[x].geom); // i.e., change last lineto to closepath
|
||||
}
|
||||
|
||||
if (layer_features[x].geom.size() > 0) {
|
||||
|
||||
Reference in New Issue
Block a user