mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 18:35:41 +02:00
Checkpoint on accepting multiple joined rows per tiled feature
This commit is contained in:
+18
-5
@@ -60,6 +60,7 @@ std::vector<std::string> unidecode_data;
|
|||||||
std::string join_tile_attribute;
|
std::string join_tile_attribute;
|
||||||
std::string join_table_expression;
|
std::string join_table_expression;
|
||||||
std::string join_table;
|
std::string join_table;
|
||||||
|
size_t join_count_limit = 1;
|
||||||
std::string attribute_for_id;
|
std::string attribute_for_id;
|
||||||
|
|
||||||
bool want_overzoom = false;
|
bool want_overzoom = false;
|
||||||
@@ -78,8 +79,11 @@ struct stats {
|
|||||||
std::vector<struct strategy> strategies{};
|
std::vector<struct strategy> strategies{};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::map<std::string, mvt_value>> get_joined_rows(sqlite3 *db, const std::vector<mvt_value> &join_keys) {
|
// list, per feature in the tile,
|
||||||
std::vector<std::map<std::string, mvt_value>> ret;
|
// of lists of features in the sqlite response,
|
||||||
|
// each of which is a mapping from keys to values
|
||||||
|
std::vector<std::vector<std::map<std::string, mvt_value>>> get_joined_rows(sqlite3 *db, const std::vector<mvt_value> &join_keys) {
|
||||||
|
std::vector<std::vector<std::map<std::string, mvt_value>>> ret;
|
||||||
ret.resize(join_keys.size());
|
ret.resize(join_keys.size());
|
||||||
|
|
||||||
// double quotes for table and column identifiers
|
// double quotes for table and column identifiers
|
||||||
@@ -109,6 +113,8 @@ std::vector<std::map<std::string, mvt_value>> get_joined_rows(sqlite3 *db, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this doesn't add a LIMIT to the query because our limit
|
||||||
|
// is per tiled feature, not a limit on the entire query response.
|
||||||
query += ");";
|
query += ");";
|
||||||
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
@@ -129,6 +135,7 @@ std::vector<std::map<std::string, mvt_value>> get_joined_rows(sqlite3 *db, const
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret[f->second].size() < join_count_limit) {
|
||||||
for (int i = 1; i < count; i++) {
|
for (int i = 1; i < count; i++) {
|
||||||
int type = sqlite3_column_type(stmt, i);
|
int type = sqlite3_column_type(stmt, i);
|
||||||
mvt_value v;
|
mvt_value v;
|
||||||
@@ -144,7 +151,8 @@ std::vector<std::map<std::string, mvt_value>> get_joined_rows(sqlite3 *db, const
|
|||||||
row.emplace(name, v);
|
row.emplace(name, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret[f->second] = std::move(row);
|
ret[f->second].push_back(std::move(row));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sqlite3_finalize(stmt) != SQLITE_OK) {
|
if (sqlite3_finalize(stmt) != SQLITE_OK) {
|
||||||
@@ -243,7 +251,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::map<std::string, mvt_value>> joined;
|
std::vector<std::vector<std::map<std::string, mvt_value>>> joined;
|
||||||
if (db != NULL) {
|
if (db != NULL) {
|
||||||
// collect join keys for sql query
|
// collect join keys for sql query
|
||||||
|
|
||||||
@@ -318,7 +326,8 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
|
|||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const &kv : joined[f]) {
|
for (auto const &joined_feature : joined[f]) {
|
||||||
|
for (auto const &kv : joined_feature) {
|
||||||
if (kv.first == attribute_for_id) {
|
if (kv.first == attribute_for_id) {
|
||||||
outfeature.has_id = true;
|
outfeature.has_id = true;
|
||||||
outfeature.id = mvt_value_to_long_long(kv.second);
|
outfeature.id = mvt_value_to_long_long(kv.second);
|
||||||
@@ -330,6 +339,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (header.size() > 0 && key == header[0]) {
|
if (header.size() > 0 && key == header[0]) {
|
||||||
std::map<std::string, std::vector<std::string>>::iterator ii = mapping.find(sv.s);
|
std::map<std::string, std::vector<std::string>>::iterator ii = mapping.find(sv.s);
|
||||||
@@ -1403,6 +1413,7 @@ int main(int argc, char **argv) {
|
|||||||
{"join-tile-attribute", required_argument, 0, '~'},
|
{"join-tile-attribute", required_argument, 0, '~'},
|
||||||
{"join-table-expression", required_argument, 0, '~'},
|
{"join-table-expression", required_argument, 0, '~'},
|
||||||
{"join-table", required_argument, 0, '~'},
|
{"join-table", required_argument, 0, '~'},
|
||||||
|
{"join-count-limit", required_argument, 0, '~'},
|
||||||
{"use-attribute-for-id", required_argument, 0, '~'},
|
{"use-attribute-for-id", required_argument, 0, '~'},
|
||||||
|
|
||||||
{"no-tile-size-limit", no_argument, &pk, 1},
|
{"no-tile-size-limit", no_argument, &pk, 1},
|
||||||
@@ -1605,6 +1616,8 @@ int main(int argc, char **argv) {
|
|||||||
attribute_for_id = optarg;
|
attribute_for_id = optarg;
|
||||||
} else if (strcmp(opt, "exclude-all-tile-attributes") == 0) {
|
} else if (strcmp(opt, "exclude-all-tile-attributes") == 0) {
|
||||||
exclude_all_tile_attributes = true;
|
exclude_all_tile_attributes = true;
|
||||||
|
} else if (strcmp(opt, "join-count-limit") == 0) {
|
||||||
|
join_count_limit = atoi(optarg);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: Unrecognized option --%s\n", argv[0], opt);
|
fprintf(stderr, "%s: Unrecognized option --%s\n", argv[0], opt);
|
||||||
exit(EXIT_ARGS);
|
exit(EXIT_ARGS);
|
||||||
|
|||||||
Reference in New Issue
Block a user