diff --git a/Makefile b/Makefile index 24f150ec..0447bc89 100644 --- a/Makefile +++ b/Makefile @@ -142,7 +142,14 @@ raw-tiles-test: ./tippecanoe -q -f -e tests/raw-tiles/raw-tiles -r1 -pC tests/raw-tiles/hackspots.geojson ./tippecanoe-decode -x generator tests/raw-tiles/raw-tiles > tests/raw-tiles/raw-tiles.json.check cmp tests/raw-tiles/raw-tiles.json.check tests/raw-tiles/raw-tiles.json - rm -rf tests/raw-tiles/raw-tiles tests/raw-tiles/compare.json.check + # Test that -z and -Z work in tippecanoe-decode + ./tippecanoe-decode -x generator -Z6 -z7 tests/raw-tiles/raw-tiles > tests/raw-tiles/raw-tiles-z67.json.check + 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 + ./tile-join -q -f -Z6 -z7 -e tests/raw-tiles/raw-tiles-z67 tests/raw-tiles/raw-tiles + ./tippecanoe-decode -x generator tests/raw-tiles/raw-tiles-z67 > 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 + rm -rf tests/raw-tiles/raw-tiles tests/raw-tiles/raw-tiles-z67 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 ./tippecanoe -q -f -e tests/raw-tiles/nothing tests/raw-tiles/nothing.geojson ./tippecanoe-decode -x generator tests/raw-tiles/nothing > tests/raw-tiles/nothing.json.check diff --git a/decode.cpp b/decode.cpp index 86e58fbd..e75248c1 100644 --- a/decode.cpp +++ b/decode.cpp @@ -268,7 +268,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set co isdir = true; db = dirmeta2tmp(fname); - tiles = enumerate_dirtiles(fname); + tiles = enumerate_dirtiles(fname, minzoom, maxzoom); } else { if (sqlite3_open(fname, &db) != SQLITE_OK) { fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db)); diff --git a/dirtiles.cpp b/dirtiles.cpp index b946e07c..a5418a12 100644 --- a/dirtiles.cpp +++ b/dirtiles.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include "jsonpull/jsonpull.h" @@ -84,7 +85,7 @@ void check_dir(const char *dir, char **argv, bool force, bool forcetable) { return; } - std::vector tiles = enumerate_dirtiles(dir); + std::vector tiles = enumerate_dirtiles(dir, INT_MIN, INT_MAX); for (size_t i = 0; i < tiles.size(); i++) { std::string fn = std::string(dir) + "/" + tiles[i].path(); @@ -101,14 +102,14 @@ void check_dir(const char *dir, char **argv, bool force, bool forcetable) { } } -std::vector enumerate_dirtiles(const char *fname) { +std::vector enumerate_dirtiles(const char *fname, int minzoom, int maxzoom) { std::vector tiles; DIR *d1 = opendir(fname); if (d1 != NULL) { struct dirent *dp; while ((dp = readdir(d1)) != NULL) { - if (numeric(dp->d_name)) { + if (numeric(dp->d_name) && atoi(dp->d_name) >= minzoom && atoi(dp->d_name) <= maxzoom) { std::string z = std::string(fname) + "/" + dp->d_name; int tz = atoi(dp->d_name); diff --git a/dirtiles.hpp b/dirtiles.hpp index 52b7f47b..6855f9aa 100644 --- a/dirtiles.hpp +++ b/dirtiles.hpp @@ -42,7 +42,7 @@ struct zxy { } }; -std::vector enumerate_dirtiles(const char *fname); +std::vector enumerate_dirtiles(const char *fname, int minzoom, int maxzoom); sqlite3 *dirmeta2tmp(const char *fname); std::string dir_read_tile(std::string pbfPath, struct zxy tile); diff --git a/serial.cpp b/serial.cpp index 98ac1ef0..149de01c 100644 --- a/serial.cpp +++ b/serial.cpp @@ -633,7 +633,6 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { sf.full_values.erase(sf.full_values.begin() + i); continue; } - } if (!sst->filters) { diff --git a/tests/raw-tiles/raw-tiles-z67-join.json b/tests/raw-tiles/raw-tiles-z67-join.json new file mode 100644 index 00000000..a9da6850 --- /dev/null +++ b/tests/raw-tiles/raw-tiles-z67-join.json @@ -0,0 +1,36 @@ +{ "type": "FeatureCollection", "properties": { +"bounds": "-123.750000,45.089036,-120.937500,47.040182", +"center": "-122.662354,45.514045,7", +"description": "tests/raw-tiles/raw-tiles", +"format": "pbf", +"json": "{\"vector_layers\": [ { \"id\": \"hackspots\", \"description\": \"\", \"minzoom\": 6, \"maxzoom\": 7, \"fields\": {\"Address\": \"String\", \"Name\": \"String\", \"Notes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"hackspots\",\"count\": 8,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"Address\",\"count\": 4,\"type\": \"string\",\"values\": [\"1507 N Rosa Parks Way Portland, OR 97217\",\"201 SE 12th Ave, Portland, OR 97214\",\"4637 N Albina Ave Portland, OR 97217\",\"915 SE Hawthorne Blvd. Portland, OR 97214\"]},{\"attribute\": \"Name\",\"count\": 4,\"type\": \"string\",\"values\": [\"Albina Press\",\"Arbor Lodge\",\"Lucky Labrador Brew Pub\",\"Three Friends Coffeehouse\"]},{\"attribute\": \"Notes\",\"count\": 3,\"type\": \"string\",\"values\": [\"\",\"Dog friendly\",\"usually busy, outlets on side wall only\"]}]}]}}", +"maxzoom": "7", +"minzoom": "6", +"name": "tests/raw-tiles/raw-tiles", +"type": "overlay", +"version": "2" +}, "features": [ +{ "type": "FeatureCollection", "properties": { "zoom": 6, "x": 10, "y": 22 }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "hackspots", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "Name": "Arbor Lodge", "Address": "1507 N Rosa Parks Way Portland, OR 97217", "Notes": "" }, "geometry": { "type": "Point", "coordinates": [ -122.682953, 45.570794 ] } } +, +{ "type": "Feature", "properties": { "Name": "Albina Press", "Address": "4637 N Albina Ave Portland, OR 97217", "Notes": "usually busy, outlets on side wall only" }, "geometry": { "type": "Point", "coordinates": [ -122.676086, 45.557333 ] } } +, +{ "type": "Feature", "properties": { "Name": "Three Friends Coffeehouse", "Address": "201 SE 12th Ave, Portland, OR 97214", "Notes": "" }, "geometry": { "type": "Point", "coordinates": [ -122.655487, 45.521744 ] } } +, +{ "type": "Feature", "properties": { "Name": "Lucky Labrador Brew Pub", "Address": "915 SE Hawthorne Blvd. Portland, OR 97214", "Notes": "Dog friendly" }, "geometry": { "type": "Point", "coordinates": [ -122.656860, 45.513084 ] } } +] } +] } +, +{ "type": "FeatureCollection", "properties": { "zoom": 7, "x": 20, "y": 45 }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "hackspots", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "Name": "Arbor Lodge", "Address": "1507 N Rosa Parks Way Portland, OR 97217", "Notes": "" }, "geometry": { "type": "Point", "coordinates": [ -122.682953, 45.570313 ] } } +, +{ "type": "Feature", "properties": { "Name": "Albina Press", "Address": "4637 N Albina Ave Portland, OR 97217", "Notes": "usually busy, outlets on side wall only" }, "geometry": { "type": "Point", "coordinates": [ -122.675400, 45.556853 ] } } +, +{ "type": "Feature", "properties": { "Name": "Three Friends Coffeehouse", "Address": "201 SE 12th Ave, Portland, OR 97214", "Notes": "" }, "geometry": { "type": "Point", "coordinates": [ -122.655487, 45.521263 ] } } +, +{ "type": "Feature", "properties": { "Name": "Lucky Labrador Brew Pub", "Address": "915 SE Hawthorne Blvd. Portland, OR 97214", "Notes": "Dog friendly" }, "geometry": { "type": "Point", "coordinates": [ -122.656860, 45.512602 ] } } +] } +] } +] } diff --git a/tests/raw-tiles/raw-tiles-z67.json b/tests/raw-tiles/raw-tiles-z67.json new file mode 100644 index 00000000..45900887 --- /dev/null +++ b/tests/raw-tiles/raw-tiles-z67.json @@ -0,0 +1,36 @@ +{ "type": "FeatureCollection", "properties": { +"bounds": "-122.682427,45.512331,-122.654961,45.569975", +"center": "-122.662354,45.514045,14", +"description": "tests/raw-tiles/raw-tiles", +"format": "pbf", +"json": "{\"vector_layers\": [ { \"id\": \"hackspots\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 14, \"fields\": {\"Address\": \"String\", \"Name\": \"String\", \"Notes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"hackspots\",\"count\": 4,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"Address\",\"count\": 4,\"type\": \"string\",\"values\": [\"1507 N Rosa Parks Way Portland, OR 97217\",\"201 SE 12th Ave, Portland, OR 97214\",\"4637 N Albina Ave Portland, OR 97217\",\"915 SE Hawthorne Blvd. Portland, OR 97214\"]},{\"attribute\": \"Name\",\"count\": 4,\"type\": \"string\",\"values\": [\"Albina Press\",\"Arbor Lodge\",\"Lucky Labrador Brew Pub\",\"Three Friends Coffeehouse\"]},{\"attribute\": \"Notes\",\"count\": 3,\"type\": \"string\",\"values\": [\"\",\"Dog friendly\",\"usually busy, outlets on side wall only\"]}]}]}}", +"maxzoom": "14", +"minzoom": "0", +"name": "tests/raw-tiles/raw-tiles", +"type": "overlay", +"version": "2" +}, "features": [ +{ "type": "FeatureCollection", "properties": { "zoom": 6, "x": 10, "y": 22, "compressed": false }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "hackspots", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "Name": "Arbor Lodge", "Address": "1507 N Rosa Parks Way Portland, OR 97217", "Notes": "" }, "geometry": { "type": "Point", "coordinates": [ -122.682953, 45.570794 ] } } +, +{ "type": "Feature", "properties": { "Name": "Albina Press", "Address": "4637 N Albina Ave Portland, OR 97217", "Notes": "usually busy, outlets on side wall only" }, "geometry": { "type": "Point", "coordinates": [ -122.676086, 45.557333 ] } } +, +{ "type": "Feature", "properties": { "Name": "Three Friends Coffeehouse", "Address": "201 SE 12th Ave, Portland, OR 97214", "Notes": "" }, "geometry": { "type": "Point", "coordinates": [ -122.655487, 45.521744 ] } } +, +{ "type": "Feature", "properties": { "Name": "Lucky Labrador Brew Pub", "Address": "915 SE Hawthorne Blvd. Portland, OR 97214", "Notes": "Dog friendly" }, "geometry": { "type": "Point", "coordinates": [ -122.656860, 45.513084 ] } } +] } +] } +, +{ "type": "FeatureCollection", "properties": { "zoom": 7, "x": 20, "y": 45, "compressed": false }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "hackspots", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "Name": "Arbor Lodge", "Address": "1507 N Rosa Parks Way Portland, OR 97217", "Notes": "" }, "geometry": { "type": "Point", "coordinates": [ -122.682953, 45.570313 ] } } +, +{ "type": "Feature", "properties": { "Name": "Albina Press", "Address": "4637 N Albina Ave Portland, OR 97217", "Notes": "usually busy, outlets on side wall only" }, "geometry": { "type": "Point", "coordinates": [ -122.675400, 45.556853 ] } } +, +{ "type": "Feature", "properties": { "Name": "Three Friends Coffeehouse", "Address": "201 SE 12th Ave, Portland, OR 97214", "Notes": "" }, "geometry": { "type": "Point", "coordinates": [ -122.655487, 45.521263 ] } } +, +{ "type": "Feature", "properties": { "Name": "Lucky Labrador Brew Pub", "Address": "915 SE Hawthorne Blvd. Portland, OR 97214", "Notes": "Dog friendly" }, "geometry": { "type": "Point", "coordinates": [ -122.656860, 45.512602 ] } } +] } +] } +] } diff --git a/tile-join.cpp b/tile-join.cpp index 2a1c62fd..9597c1c2 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -409,7 +409,7 @@ struct reader *begin_reading(char *fname) { r->stmt = NULL; r->next = NULL; - r->dirtiles = enumerate_dirtiles(fname); + r->dirtiles = enumerate_dirtiles(fname, minzoom, maxzoom); r->dirbase = fname; if (r->dirtiles.size() == 0) {