mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Add a feature to exclude a key from the joined tileset
This commit is contained in:
+53
-40
@@ -89,7 +89,7 @@ static inline int compress(std::string const &input, std::string &output) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle(std::string message, int z, unsigned x, unsigned y, struct pool **file_keys, char ***layernames, int *nlayers, sqlite3 *outdb, std::vector<std::string> &header, std::map<std::string, std::vector<std::string> > &mapping) {
|
void handle(std::string message, int z, unsigned x, unsigned y, struct pool **file_keys, char ***layernames, int *nlayers, sqlite3 *outdb, std::vector<std::string> &header, std::map<std::string, std::vector<std::string> > &mapping, struct pool *exclude) {
|
||||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||||
|
|
||||||
// https://github.com/mapbox/mapnik-vector-tile/blob/master/examples/c%2B%2B/tileinfo.cpp
|
// https://github.com/mapbox/mapnik-vector-tile/blob/master/examples/c%2B%2B/tileinfo.cpp
|
||||||
@@ -197,27 +197,29 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_pooled(&((*file_keys)[ll]), key, type)) {
|
if (!is_pooled(exclude, key, VT_STRING)) {
|
||||||
pool(&((*file_keys)[ll]), strdup(key), type);
|
if (!is_pooled(&((*file_keys)[ll]), key, type)) {
|
||||||
|
pool(&((*file_keys)[ll]), strdup(key), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pool_val *k, *v;
|
||||||
|
|
||||||
|
if (is_pooled(&keys, key, VT_STRING)) {
|
||||||
|
k = pool(&keys, key, VT_STRING);
|
||||||
|
} else {
|
||||||
|
k = pool(&keys, strdup(key), VT_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_pooled(&values, value, type)) {
|
||||||
|
v = pool(&values, value, type);
|
||||||
|
} else {
|
||||||
|
v = pool(&values, strdup(value), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
outfeature->add_tags(k->n);
|
||||||
|
outfeature->add_tags(v->n);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pool_val *k, *v;
|
|
||||||
|
|
||||||
if (is_pooled(&keys, key, VT_STRING)) {
|
|
||||||
k = pool(&keys, key, VT_STRING);
|
|
||||||
} else {
|
|
||||||
k = pool(&keys, strdup(key), VT_STRING);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_pooled(&values, value, type)) {
|
|
||||||
v = pool(&values, value, type);
|
|
||||||
} else {
|
|
||||||
v = pool(&values, strdup(value), type);
|
|
||||||
}
|
|
||||||
|
|
||||||
outfeature->add_tags(k->n);
|
|
||||||
outfeature->add_tags(v->n);
|
|
||||||
|
|
||||||
if (strcmp(key, header[0].c_str()) == 0) {
|
if (strcmp(key, header[0].c_str()) == 0) {
|
||||||
std::map<std::string, std::vector<std::string> >::iterator ii = mapping.find(std::string(value));
|
std::map<std::string, std::vector<std::string> >::iterator ii = mapping.find(std::string(value));
|
||||||
|
|
||||||
@@ -240,24 +242,28 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
|
|||||||
const char *sjoinkey = joinkey.c_str();
|
const char *sjoinkey = joinkey.c_str();
|
||||||
const char *sjoinval = joinval.c_str();
|
const char *sjoinval = joinval.c_str();
|
||||||
|
|
||||||
if (!is_pooled(&((*file_keys)[ll]), sjoinkey, type)) {
|
if (!is_pooled(exclude, sjoinkey, VT_STRING)) {
|
||||||
pool(&((*file_keys)[ll]), strdup(sjoinkey), type);
|
if (!is_pooled(&((*file_keys)[ll]), sjoinkey, type)) {
|
||||||
}
|
pool(&((*file_keys)[ll]), strdup(sjoinkey), type);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_pooled(&keys, sjoinkey, VT_STRING)) {
|
struct pool_val *k, *v;
|
||||||
k = pool(&keys, sjoinkey, VT_STRING);
|
|
||||||
} else {
|
|
||||||
k = pool(&keys, strdup(sjoinkey), VT_STRING);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_pooled(&values, sjoinval, type)) {
|
if (is_pooled(&keys, sjoinkey, VT_STRING)) {
|
||||||
v = pool(&values, sjoinval, type);
|
k = pool(&keys, sjoinkey, VT_STRING);
|
||||||
} else {
|
} else {
|
||||||
v = pool(&values, strdup(sjoinval), type);
|
k = pool(&keys, strdup(sjoinkey), VT_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
outfeature->add_tags(k->n);
|
if (is_pooled(&values, sjoinval, type)) {
|
||||||
outfeature->add_tags(v->n);
|
v = pool(&values, sjoinval, type);
|
||||||
|
} else {
|
||||||
|
v = pool(&values, strdup(sjoinval), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
outfeature->add_tags(k->n);
|
||||||
|
outfeature->add_tags(v->n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,7 +306,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
|
|||||||
mbtiles_write_tile(outdb, z, x, y, compressed.data(), compressed.size());
|
mbtiles_write_tile(outdb, z, x, y, compressed.data(), compressed.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void decode(char *fname, char *map, struct pool **file_keys, char ***layernames, int *nlayers, sqlite3 *outdb, struct stats *st, std::vector<std::string> &header, std::map<std::string, std::vector<std::string> > &mapping) {
|
void decode(char *fname, char *map, struct pool **file_keys, char ***layernames, int *nlayers, sqlite3 *outdb, struct stats *st, std::vector<std::string> &header, std::map<std::string, std::vector<std::string> > &mapping, struct pool *exclude) {
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
|
|
||||||
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
||||||
@@ -326,7 +332,7 @@ void decode(char *fname, char *map, struct pool **file_keys, char ***layernames,
|
|||||||
|
|
||||||
fprintf(stderr, "%lld/%lld/%lld \r", zoom, x, y);
|
fprintf(stderr, "%lld/%lld/%lld \r", zoom, x, y);
|
||||||
|
|
||||||
handle(std::string(s, len), zoom, x, y, file_keys, layernames, nlayers, outdb, header, mapping);
|
handle(std::string(s, len), zoom, x, y, file_keys, layernames, nlayers, outdb, header, mapping, exclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
@@ -365,7 +371,7 @@ void decode(char *fname, char *map, struct pool **file_keys, char ***layernames,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void usage(char **argv) {
|
void usage(char **argv) {
|
||||||
fprintf(stderr, "Usage: %s [-f] [-c joins.csv] -o new.mbtiles source.mbtiles\n", argv[0]);
|
fprintf(stderr, "Usage: %s [-f] [-c joins.csv] [-x exclude ...] -o new.mbtiles source.mbtiles\n", argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,11 +458,14 @@ int main(int argc, char **argv) {
|
|||||||
std::vector<std::string> header;
|
std::vector<std::string> header;
|
||||||
std::map<std::string, std::vector<std::string> > mapping;
|
std::map<std::string, std::vector<std::string> > mapping;
|
||||||
|
|
||||||
|
struct pool exclude;
|
||||||
|
pool_init(&exclude, 0);
|
||||||
|
|
||||||
extern int optind;
|
extern int optind;
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
while ((i = getopt(argc, argv, "fo:c:")) != -1) {
|
while ((i = getopt(argc, argv, "fo:c:x:")) != -1) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 'o':
|
case 'o':
|
||||||
outfile = optarg;
|
outfile = optarg;
|
||||||
@@ -476,6 +485,10 @@ int main(int argc, char **argv) {
|
|||||||
readcsv(csv, header, mapping);
|
readcsv(csv, header, mapping);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
pool(&exclude, optarg, VT_STRING);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage(argv);
|
usage(argv);
|
||||||
}
|
}
|
||||||
@@ -498,7 +511,7 @@ int main(int argc, char **argv) {
|
|||||||
int nlayers = 0;
|
int nlayers = 0;
|
||||||
|
|
||||||
for (i = optind; i < argc; i++) {
|
for (i = optind; i < argc; i++) {
|
||||||
decode(argv[i], csv, &file_keys, &layernames, &nlayers, outdb, &st, header, mapping);
|
decode(argv[i], csv, &file_keys, &layernames, &nlayers, outdb, &st, header, mapping, &exclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nlayers; i++) {
|
for (i = 0; i < nlayers; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user