Fix -Z and -z for tile directories in tile-join and tippecanoe-decode

This commit is contained in:
Eric Fischer 2019-03-18 18:01:32 -07:00
parent 945d80400b
commit 25b9c51ac8
8 changed files with 87 additions and 8 deletions

View File

@ -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

View File

@ -268,7 +268,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> 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));

View File

@ -7,6 +7,7 @@
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <sys/stat.h>
#include <sqlite3.h>
#include "jsonpull/jsonpull.h"
@ -84,7 +85,7 @@ void check_dir(const char *dir, char **argv, bool force, bool forcetable) {
return;
}
std::vector<zxy> tiles = enumerate_dirtiles(dir);
std::vector<zxy> 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<zxy> enumerate_dirtiles(const char *fname) {
std::vector<zxy> enumerate_dirtiles(const char *fname, int minzoom, int maxzoom) {
std::vector<zxy> 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);

View File

@ -42,7 +42,7 @@ struct zxy {
}
};
std::vector<zxy> enumerate_dirtiles(const char *fname);
std::vector<zxy> 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);

View File

@ -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) {

View File

@ -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 ] } }
] }
] }
] }

View File

@ -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 ] } }
] }
] }
] }

View File

@ -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) {