Pmtiles tests pass now too

This commit is contained in:
Erica Fischer
2022-12-27 14:18:59 -08:00
parent 1cb467a382
commit fa37859adb
10 changed files with 21 additions and 13 deletions
+4 -4
View File
@@ -177,19 +177,19 @@ pmtiles-test:
# From raw-tiles-test: # From raw-tiles-test:
./tippecanoe -q -f -o tests/raw-tiles/raw-tiles.pmtiles -r1 -pC tests/raw-tiles/hackspots.geojson ./tippecanoe -q -f -o tests/raw-tiles/raw-tiles.pmtiles -r1 -pC tests/raw-tiles/hackspots.geojson
./tippecanoe-decode -x generator tests/raw-tiles/raw-tiles.pmtiles > tests/raw-tiles/raw-tiles.json.check ./tippecanoe-decode -x generator tests/raw-tiles/raw-tiles.pmtiles | sed 's/\.pmtiles//g' | sed 's/ -o / -e /g' > tests/raw-tiles/raw-tiles.json.check
cmp tests/raw-tiles/raw-tiles.json.check tests/raw-tiles/raw-tiles.json cmp tests/raw-tiles/raw-tiles.json.check tests/raw-tiles/raw-tiles.json
# Test that -z and -Z work in tippecanoe-decode # Test that -z and -Z work in tippecanoe-decode
./tippecanoe-decode -x generator -Z6 -z7 tests/raw-tiles/raw-tiles.pmtiles > tests/raw-tiles/raw-tiles-z67.json.check ./tippecanoe-decode -x generator -Z6 -z7 tests/raw-tiles/raw-tiles.pmtiles | sed 's/\.pmtiles//g' | sed 's/ -o / -e /g' > tests/raw-tiles/raw-tiles-z67.json.check
cmp tests/raw-tiles/raw-tiles-z67.json.check tests/raw-tiles/raw-tiles-z67.json cmp tests/raw-tiles/raw-tiles-z67.json.check tests/raw-tiles/raw-tiles-z67.json
# Test that -z and -Z work in tile-join # Test that -z and -Z work in tile-join
./tile-join -q -f -Z6 -z7 -o tests/raw-tiles/raw-tiles-z67.pmtiles tests/raw-tiles/raw-tiles.pmtiles ./tile-join -q -f -Z6 -z7 -o tests/raw-tiles/raw-tiles-z67.pmtiles tests/raw-tiles/raw-tiles.pmtiles
./tippecanoe-decode -x generator tests/raw-tiles/raw-tiles-z67.pmtiles > tests/raw-tiles/raw-tiles-z67-join.json.check ./tippecanoe-decode -x generator tests/raw-tiles/raw-tiles-z67.pmtiles | sed 's/\.pmtiles//g' | sed 's/ -o / -e /g' > tests/raw-tiles/raw-tiles-z67-join.json.check
cmp tests/raw-tiles/raw-tiles-z67-join.json.check tests/raw-tiles/raw-tiles-z67-join.json cmp tests/raw-tiles/raw-tiles-z67-join.json.check tests/raw-tiles/raw-tiles-z67-join.json
rm -rf tests/raw-tiles/raw-tiles.pmtiles tests/raw-tiles/raw-tiles-z67.pmtiles tests/raw-tiles/raw-tiles.json.check raw-tiles-z67.json.check tests/raw-tiles/raw-tiles-z67-join.json.check rm -rf tests/raw-tiles/raw-tiles.pmtiles tests/raw-tiles/raw-tiles-z67.pmtiles tests/raw-tiles/raw-tiles.json.check raw-tiles-z67.json.check tests/raw-tiles/raw-tiles-z67-join.json.check
# Test that metadata.json is created even if all features are clipped away # Test that metadata.json is created even if all features are clipped away
./tippecanoe -q -f -o tests/raw-tiles/nothing.pmtiles tests/raw-tiles/nothing.geojson ./tippecanoe -q -f -o tests/raw-tiles/nothing.pmtiles tests/raw-tiles/nothing.geojson
./tippecanoe-decode -x generator tests/raw-tiles/nothing.pmtiles > tests/raw-tiles/nothing.json.check ./tippecanoe-decode -x generator tests/raw-tiles/nothing.pmtiles | sed 's/\.pmtiles//g' | sed 's/ -o / -e /g' > tests/raw-tiles/nothing.json.check
cmp tests/raw-tiles/nothing.json.check tests/raw-tiles/nothing.json cmp tests/raw-tiles/nothing.json.check tests/raw-tiles/nothing.json
rm -r tests/raw-tiles/nothing.pmtiles tests/raw-tiles/nothing.json.check rm -r tests/raw-tiles/nothing.pmtiles tests/raw-tiles/nothing.json.check
+4 -2
View File
@@ -275,6 +275,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
char *pmtiles_map; char *pmtiles_map;
std::vector<pmtiles::entry_zxy> entries; std::vector<pmtiles::entry_zxy> entries;
bool is_pmtiles = false;
if (stat(fname, &st) == 0 && (st.st_mode & S_IFDIR) != 0) { if (stat(fname, &st) == 0 && (st.st_mode & S_IFDIR) != 0) {
isdir = true; isdir = true;
@@ -294,6 +295,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
} }
db = pmtilesmeta2tmp(fname, pmtiles_map); db = pmtilesmeta2tmp(fname, pmtiles_map);
entries = pmtiles_entries_zxy(pmtiles_map, minzoom, maxzoom); entries = pmtiles_entries_zxy(pmtiles_map, minzoom, maxzoom);
is_pmtiles = true;
} else { } else {
if (sqlite3_open(fname, &db) != SQLITE_OK) { if (sqlite3_open(fname, &db) != SQLITE_OK) {
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db)); fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
@@ -399,7 +401,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
handle(s, tiles[i].z, tiles[i].x, tiles[i].y, to_decode, pipeline, stats, state, coordinate_mode); handle(s, tiles[i].z, tiles[i].x, tiles[i].y, to_decode, pipeline, stats, state, coordinate_mode);
} }
} else if (entries.size() > 0) { } else if (is_pmtiles) {
within = 0; within = 0;
for (auto const &entry : entries) { for (auto const &entry : entries) {
@@ -484,7 +486,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
} else { } else {
int handled = 0; int handled = 0;
while (z >= 0 && !handled) { while (z >= 0 && !handled) {
if (entries.size() > 0) { if (is_pmtiles) {
uint64_t tile_offset; uint64_t tile_offset;
uint32_t tile_length; uint32_t tile_length;
std::tie(tile_offset, tile_length) = pmtiles_get_tile(pmtiles_map, z, x, y); std::tie(tile_offset, tile_length) = pmtiles_get_tile(pmtiles_map, z, x, y);
+6
View File
@@ -421,17 +421,22 @@ sqlite3 *pmtilesmeta2tmp(const char *fname, const char *pmtiles_map) {
bool has_json = false; bool has_json = false;
std::string buf; std::string buf;
json_writer state(&buf); json_writer state(&buf);
state.nospace = true;
state.json_write_hash(); state.json_write_hash();
for (size_t i = 0; i < o->value.object.length; i++) { for (size_t i = 0; i < o->value.object.length; i++) {
const char *key = o->value.object.keys[i]->value.string.string; const char *key = o->value.object.keys[i]->value.string.string;
if (strcmp(key, "vector_layers") == 0 && o->value.object.values[i]->type == JSON_ARRAY) { if (strcmp(key, "vector_layers") == 0 && o->value.object.values[i]->type == JSON_ARRAY) {
has_json = true; has_json = true;
state.nospace = true;
state.json_write_string("vector_layers"); state.json_write_string("vector_layers");
state.nospace = true;
state.json_write_json(json_stringify(o->value.object.values[i])); state.json_write_json(json_stringify(o->value.object.values[i]));
} else if (strcmp(key, "tilestats") == 0 && o->value.object.values[i]->type == JSON_HASH) { } else if (strcmp(key, "tilestats") == 0 && o->value.object.values[i]->type == JSON_HASH) {
has_json = true; has_json = true;
state.nospace = true;
state.json_write_string("tilestats"); state.json_write_string("tilestats");
state.nospace = true;
state.json_write_json(json_stringify(o->value.object.values[i])); state.json_write_json(json_stringify(o->value.object.values[i]));
} else if (strcmp(key, "strategies") == 0 && o->value.object.values[i]->type == JSON_ARRAY) { } else if (strcmp(key, "strategies") == 0 && o->value.object.values[i]->type == JSON_ARRAY) {
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('strategies', %Q);", json_stringify(o->value.object.values[i])); sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('strategies', %Q);", json_stringify(o->value.object.values[i]));
@@ -452,6 +457,7 @@ sqlite3 *pmtilesmeta2tmp(const char *fname, const char *pmtiles_map) {
} }
json_end(jp); json_end(jp);
state.nospace = true;
state.json_end_hash(); state.json_end_hash();
if (has_json) { if (has_json) {