Skip to content

Commit

Permalink
Gathering join keys for sql query
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Dec 4, 2024
1 parent 36b207c commit 0ae73c1
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions tile-join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bool exclude_all = false;
std::vector<std::string> unidecode_data;
std::string join_tile_column;
std::string join_table_column;
std::string join_table;

bool want_overzoom = false;
int buffer = 5;
Expand Down Expand Up @@ -143,6 +144,27 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
}
}

if (db != NULL) {
// collect join keys for sql query

std::vector<mvt_value> join_keys;
join_keys.resize(layer.features.size());

for (size_t f = 0; f < layer.features.size(); f++) {
mvt_feature &feat = layer.features[f];
join_keys[f].type = mvt_no_such_key;

for (size_t t = 0; t + 1 < feat.tags.size(); t += 2) {
const std::string &key = layer.keys[feat.tags[t]];
if (key == join_tile_column) {
const mvt_value &val = layer.values[feat.tags[t + 1]];
join_keys[f] = val;
break;
}
}
}
}

auto tilestats = layermap.find(layer.name);

for (size_t f = 0; f < layer.features.size(); f++) {
Expand Down Expand Up @@ -1263,8 +1285,9 @@ int main(int argc, char **argv) {
{"read-from", required_argument, 0, 'r'},

{"join-sqlite", required_argument, 0, '~'},
{"join-tile-key", required_argument, 0, '~'},
{"join-table-key", required_argument, 0, '~'},
{"join-tile-column", required_argument, 0, '~'},
{"join-table-column", required_argument, 0, '~'},
{"join-table", required_argument, 0, '~'},

{"no-tile-size-limit", no_argument, &pk, 1},
{"no-tile-compression", no_argument, &pC, 1},
Expand Down Expand Up @@ -1452,6 +1475,12 @@ int main(int argc, char **argv) {
unidecode_data = read_unidecode(optarg);
} else if (strcmp(opt, "join-sqlite") == 0) {
join_sqlite_fname = optarg;
} else if (strcmp(opt, "join-table") == 0) {
join_table = optarg;
} else if (strcmp(opt, "join-table-column") == 0) {
join_table_column = optarg;
} else if (strcmp(opt, "join-tile-column") == 0) {
join_tile_column = optarg;
} else {
fprintf(stderr, "%s: Unrecognized option --%s\n", argv[0], opt);
exit(EXIT_ARGS);
Expand Down

0 comments on commit 0ae73c1

Please sign in to comment.