Compare commits

..
Author SHA1 Message Date
Erica Fischer 8b362b0cd7 Griddy, but could be a lot worse 2023-01-04 16:50:01 -08:00
Erica Fischer 829c765d5d Somewhat less shardy 2023-01-04 14:51:20 -08:00
Erica FischerandBrandon Liu 3b2599f587 Add support for pmtiles output format (#55)
* add pmtiles.hpp from github.com/protomaps/PMTiles [#10]

* tippecanoe main writes pmtiles output. [#10]

* detect output format using suffix
* after mbtiles is done writing, replace with pmtiles based on map/image tables.
* add method to write_json for writing json sub-object.

* tippecanoe-decode reads pmtiles input. [#10]

* tile-join reads and writes pmtiles. [#10]

* pmtiles test suite for decode and tile-join [#10]

* add base GitHub CI action for compiling and test suite.

* update pmtiles.hpp with z>15 fix

* Fix some ordering problems with pmtiles decode

* Pmtiles should also pass the raw tiles tests

* Eradicate spaces from tileset metadata JSON fields

* Eradicate spaces from more test fixtures

* Update more tests

* Pmtiles tests pass now too

* Remove unnecessary sort (and make indent)

* Update changelog

* The allow-existing test for pmtiles needs -o, not -e

* Declare --allow-existing to be unsupported for pmtiles.

It was always a bad idea even for mbtiles.

Co-authored-by: Brandon Liu <bdon@bdon.org>
2022-12-29 12:00:13 -08:00
Sam Hashemi a374263466 Update README (#54) 2022-12-28 14:06:42 -08:00
11 changed files with 94 additions and 41 deletions
+4
View File
@@ -1,3 +1,7 @@
## 2.17.0
* Add pmtiles output format
## 2.16.0
* During tiling, limit the size of the statistics that are kept for -as-needed calculations, because they can get quite large for sources with hundreds of millions of features.
+7 -8
View File
@@ -82,7 +82,7 @@ indent:
TESTS = $(wildcard tests/*/out/*.json)
SPACE = $(NULL) $(NULL)
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) raw-tiles-test parallel-test pbf-test join-test enumerate-test decode-test join-filter-test unit json-tool-test allow-existing-test csv-test layer-json-test pmtiles-test
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) raw-tiles-test parallel-test pbf-test join-test enumerate-test decode-test join-filter-test unit json-tool-test allow-existing-test csv-test layer-json-test pmtiles-test decode-pmtiles-test
./unit
suffixes = json json.gz
@@ -373,15 +373,14 @@ allow-existing-test:
./tippecanoe-decode -x generator -x generator_options tests/allow-existing/both.dir | sed 's/both\.dir/both.mbtiles/g' > tests/allow-existing/both.dir.json.check
cmp tests/allow-existing/both.dir.json.check tests/allow-existing/both.mbtiles.json
# Make a tileset
./tippecanoe -q -Z0 -z0 -f -e tests/allow-existing/both.pmtiles tests/coalesce-tract/tl_2010_06001_tract10.json
./tippecanoe -q -Z0 -z0 -f -o tests/allow-existing/both.pmtiles tests/coalesce-tract/tl_2010_06001_tract10.json
# Writing to existing should fail
if ./tippecanoe -q -Z1 -z1 -e tests/allow-existing/both.pmtiles tests/coalesce-tract/tl_2010_06001_tract10.json; then exit 1; else exit 0; fi
if ./tippecanoe -q -Z1 -z1 -o tests/allow-existing/both.pmtiles tests/coalesce-tract/tl_2010_06001_tract10.json; then exit 1; else exit 0; fi
# Replace existing
./tippecanoe -q -Z8 -z9 -f -e tests/allow-existing/both.pmtiles tests/coalesce-tract/tl_2010_06001_tract10.json
./tippecanoe -q -Z10 -z11 -F -e tests/allow-existing/both.pmtiles tests/coalesce-tract/tl_2010_06001_tract10.json
./tippecanoe-decode -x generator -x generator_options tests/allow-existing/both.pmtiles | sed 's/both\.pmtiles/both.mbtiles/g' > tests/allow-existing/both.pmtiles.json.check
cmp tests/allow-existing/both.pmtiles.json.check tests/allow-existing/both.mbtiles.json
rm -r tests/allow-existing/both.pmtiles.json.check tests/allow-existing/both.pmtiles tests/allow-existing/both.dir.json.check tests/allow-existing/both.dir tests/allow-existing/both.mbtiles.json.check tests/allow-existing/both.mbtiles
./tippecanoe -q -Z8 -z9 -f -o tests/allow-existing/both.pmtiles tests/coalesce-tract/tl_2010_06001_tract10.json
# Allow-existing is not supported for pmtiles
if ./tippecanoe -q -Z10 -z11 -F -o tests/allow-existing/both.pmtiles tests/coalesce-tract/tl_2010_06001_tract10.json; then exit 1; else exit 0; fi
rm -r tests/allow-existing/both.pmtiles tests/allow-existing/both.dir.json.check tests/allow-existing/both.dir tests/allow-existing/both.mbtiles.json.check tests/allow-existing/both.mbtiles
csv-test:
# Reading from named CSV
+2 -5
View File
@@ -4,12 +4,9 @@ tippecanoe
Builds [vector tilesets](https://github.com/mapbox/vector-tile-spec/) from large (or small) collections of [GeoJSON](http://geojson.org/), [FlatGeobuf](https://github.com/flatgeobuf/flatgeobuf), or [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) features,
[like these](MADE_WITH.md).
This intends to be an actively maintained fork of [tippecanoe](https://github.com/mapbox/tippecanoe) originally developed by [Erica Fischer](https://github.com/e-n-f) at Mapbox. Version 2.0.0 is equivalent to [1.36.0](https://github.com/mapbox/tippecanoe/tree/1.36.0) in the original repository. Thank you Mapbox and Erica for an incredible tool!
Key features of this fork include:
* Support for [FlatGeobuf](https://github.com/flatgeobuf/flatgeobuf) input which is more compact and 5-10x faster than GeoJsonSeq input.
This is the official home of Tippecanoe, developed and actively maintained by [Erica Fischer](https://github.com/e-n-f) at [Felt](https://felt.com).
Version 2.0.0 is equivalent to [1.36.0](https://github.com/mapbox/tippecanoe/tree/1.36.0) in the original repository. Thank you Mapbox for the many years of early support.
Intent
------
+37 -15
View File
@@ -869,9 +869,17 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t ke
double distance = std::fabs(temp_dist);
if ((distance > e || kept < retain) && distance > max_distance) {
farthest_element_index = i;
max_distance = distance;
if ((distance > e || kept < retain) && distance >= max_distance) {
if (distance > max_distance) {
farthest_element_index = i;
max_distance = distance;
} else if (geom[i].y > geom[farthest_element_index].y) {
farthest_element_index = i;
max_distance = distance;
} else if (geom[i].y == geom[farthest_element_index].y && geom[i].x == geom[farthest_element_index].x) {
farthest_element_index = i;
max_distance = distance;
}
}
}
@@ -926,7 +934,7 @@ drawvec impose_tile_boundaries(drawvec &geom, long long extent) {
return out;
}
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes) {
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes, std::set<std::pair<long long, long long>> &kept) {
int res = 1 << (32 - detail - z);
long long area = 1LL << (32 - z);
@@ -939,6 +947,11 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
geom[i].necessary = 1;
}
auto found = kept.find(std::pair<long long, long long>((long long) geom[i].x, (long long) geom[i].y));
if (found != kept.end()) {
geom[i].necessary = 1;
}
if (prevent[P_SIMPLIFY_SHARED_NODES]) {
auto pt = std::lower_bound(shared_nodes.begin(), shared_nodes.end(), geom[i]);
if (pt != shared_nodes.end() && *pt == geom[i]) {
@@ -963,20 +976,28 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
geom[i].necessary = 1;
geom[j - 1].necessary = 1;
// empirical mapping from douglas-peucker simplifications
// to visvalingam simplifications that yield similar
// output sizes
double sim = simplification * (0.1596 * z + 0.878);
double scale = (res * sim) * (res * sim);
scale = exp(1.002 * log(scale) + 0.3043);
size_t start = i;
for (size_t k = start + 1; k <= j - 1; k++) {
if (geom[k].necessary) {
if (k - start > 1) {
// empirical mapping from douglas-peucker simplifications
// to visvalingam simplifications that yield similar
// output sizes
double sim = simplification * (0.1596 * z + 0.878);
double scale = (res * sim) * (res * sim);
scale = exp(1.002 * log(scale) + 0.3043);
if (j - i > 1) {
if (additional[A_VISVALINGAM]) {
visvalingam(geom, i, j, scale, retain);
} else {
douglas_peucker(geom, i, j - i, res * simplification, 2, retain);
if (additional[A_VISVALINGAM]) {
visvalingam(geom, start, k + 1, scale, retain);
} else {
douglas_peucker(geom, start, k + 1 - start, res * simplification, 2, retain);
}
}
start = k;
}
}
i = j - 1;
}
}
@@ -985,6 +1006,7 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].necessary) {
out.push_back(geom[i]);
kept.insert(std::pair<long long, long long>((long long) geom[i].x, (long long) geom[i].y));
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
#define GEOMETRY_HPP
#include <vector>
#include <set>
#include <atomic>
#include <sqlite3.h>
#include <stdio.h>
@@ -71,7 +72,7 @@ drawvec clip_lines(drawvec &geom, int z, long long buffer);
drawvec stairstep(drawvec &geom, int z, int detail);
bool point_within_tile(long long x, long long y, int z);
int quick_check(long long *bbox, int z, long long buffer);
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes);
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes, std::set<std::pair<long long, long long>> &kept);
drawvec reorder_lines(drawvec &geom);
drawvec fix_polygon(drawvec &geom);
std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms);
+1 -1
View File
@@ -3475,7 +3475,7 @@ int main(int argc, char **argv) {
unlink(out_mbtiles);
} else {
if (pmtiles_has_suffix(out_mbtiles)) {
check_pmtiles(out_mbtiles, argv);
check_pmtiles(out_mbtiles, argv, forcetable);
}
}
+6 -1
View File
@@ -25,11 +25,16 @@ bool pmtiles_has_suffix(const char *filename) {
return false;
}
void check_pmtiles(const char *filename, char **argv) {
void check_pmtiles(const char *filename, char **argv, bool forcetable) {
struct stat st;
if (stat(filename, &st) == 0) {
fprintf(stderr, "%s: Tileset \"%s\" already exists. You can use --force if you want to delete the old tileset.\n", argv[0], filename);
fprintf(stderr, "%s: %s: file exists\n", argv[0], filename);
if (forcetable) {
fprintf(stderr, "%s: --allow-existing is not supported for pmtiles\n", argv[0]);
}
exit(EXIT_EXISTS);
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
#include "mbtiles.hpp"
bool pmtiles_has_suffix(const char *filename);
void check_pmtiles(const char *filename, char **argv);
void check_pmtiles(const char *filename, char **argv, bool forcetable);
void mbtiles_map_image_to_pmtiles(char *dbname, metadata m, bool tile_compression, bool quiet, bool quiet_progress);
+1 -1
View File
@@ -1190,7 +1190,7 @@ int main(int argc, char **argv) {
unlink(out_mbtiles);
} else {
if (pmtiles_has_suffix(out_mbtiles)) {
check_pmtiles(out_mbtiles, argv);
check_pmtiles(out_mbtiles, argv, false);
}
}
+32 -7
View File
@@ -517,7 +517,7 @@ drawvec revive_polygon(drawvec &geom, double area, int z, int detail) {
}
}
double simplify_partial(partial *p, drawvec &shared_nodes) {
double simplify_partial(partial *p, drawvec &shared_nodes, std::set<std::pair<long long, long long>> &kept) {
drawvec geom;
for (size_t j = 0; j < p->geoms.size(); j++) {
@@ -566,7 +566,7 @@ double simplify_partial(partial *p, drawvec &shared_nodes) {
}
// continues to simplify to line_detail even if we have extra detail
drawvec ngeom = simplify_lines(geom, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), p->simplification, t == VT_POLYGON ? 4 : 0, shared_nodes);
drawvec ngeom = simplify_lines(geom, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), p->simplification, t == VT_POLYGON ? 4 : 0, shared_nodes, kept);
if (t != VT_POLYGON || ngeom.size() >= 3) {
geom = ngeom;
@@ -586,10 +586,31 @@ double simplify_partial(partial *p, drawvec &shared_nodes) {
void *partial_feature_worker(void *v) {
struct partial_arg *a = (struct partial_arg *) v;
std::vector<struct partial> *partials = a->partials;
std::set<std::pair<long long, long long>> kept;
for (size_t i = 0; i < (*partials).size(); i++) {
for (size_t j = 0; j < (*partials)[i].geoms.size(); j++) {
(*partials)[i].geoms[j] = remove_noop((*partials)[i].geoms[j], (*partials)[i].t, 0);
}
}
for (size_t n = 0; n < 20; n++) {
size_t before = kept.size();
for (size_t i = a->task; i < (*partials).size(); i += a->tasks) {
auto stash = (*partials)[i].geoms;
double area = simplify_partial(&((*partials)[i]), *(a->shared_nodes), kept);
(*partials)[i].geoms = stash;
}
printf("%zu nodes kept\n", kept.size());
if (kept.size() == before) {
break;
}
}
for (size_t i = a->task; i < (*partials).size(); i += a->tasks) {
double area = simplify_partial(&((*partials)[i]), *(a->shared_nodes));
double area = simplify_partial(&((*partials)[i]), *(a->shared_nodes), kept);
signed char t = (*partials)[i].t;
int z = (*partials)[i].z;
int out_detail = (*partials)[i].extra_detail;
@@ -1001,6 +1022,7 @@ bool find_common_edges(std::vector<partial> &partials, int z, int line_detail, d
// Simplify each arc
std::vector<drawvec> simplified_arcs;
std::set<std::pair<long long, long long>> kept;
size_t count = 0;
for (auto ai = arcs.begin(); ai != arcs.end(); ++ai) {
@@ -1017,7 +1039,7 @@ bool find_common_edges(std::vector<partial> &partials, int z, int line_detail, d
}
}
if (!(prevent[P_SIMPLIFY] || (z == maxzoom && prevent[P_SIMPLIFY_LOW]) || (z < maxzoom && additional[A_GRID_LOW_ZOOMS]))) {
simplified_arcs[ai->second] = simplify_lines(dv, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, 4, drawvec());
simplified_arcs[ai->second] = simplify_lines(dv, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, 4, drawvec(), kept);
} else {
simplified_arcs[ai->second] = dv;
}
@@ -2215,9 +2237,10 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
unsimplified_geometry_size += sf.geometry.size() * sizeof(draw);
if (unsimplified_geometry_size > 10 * 1024 * 1024 && !additional[A_DETECT_SHARED_BORDERS]) {
drawvec dv;
std::set<std::pair<long long, long long>> keptp;
for (; simplified_geometry_through < partials.size(); simplified_geometry_through++) {
simplify_partial(&partials[simplified_geometry_through], dv);
simplify_partial(&partials[simplified_geometry_through], dv, keptp);
for (auto &g : partials[simplified_geometry_through].geoms) {
if (partials[simplified_geometry_through].t == VT_POLYGON) {
@@ -2327,6 +2350,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
if (tasks < 1) {
tasks = 1;
}
tasks = 1;
pthread_t pthreads[tasks];
std::vector<partial_arg> args;
@@ -2445,12 +2469,13 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
layer_features = out;
std::set<std::pair<long long, long long>> keptp;
out.clear();
for (size_t x = 0; x < layer_features.size(); x++) {
if (layer_features[x].coalesced && layer_features[x].type == VT_LINE) {
layer_features[x].geom = remove_noop(layer_features[x].geom, layer_features[x].type, 0);
layer_features[x].geom = simplify_lines(layer_features[x].geom, 32, 0,
!(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x].type == VT_POLYGON ? 4 : 0, shared_nodes);
!(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x].type == VT_POLYGON ? 4 : 0, shared_nodes, keptp);
}
if (layer_features[x].type == VT_POLYGON) {
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP
#define VERSION "v2.16.0"
#define VERSION "v2.17.0"
#endif