Merge pull request #118 from mapbox/tile-join-multi

Let tile-join combine non-conflicting tilesets together
This commit is contained in:
Eric Fischer 2015-11-24 13:40:12 -08:00
commit 024c685759

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <sqlite3.h>
#include <limits.h>
#include <vector>
#include <string>
#include <map>
@ -216,7 +217,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
feature_tags.push_back(v->n);
}
if (strcmp(key, header[0].c_str()) == 0) {
if (header.size() > 0 && strcmp(key, header[0].c_str()) == 0) {
std::map<std::string, std::vector<std::string> >::iterator ii = mapping.find(std::string(value));
if (ii != mapping.end()) {
@ -322,6 +323,22 @@ 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());
}
double min(double a, double b) {
if (a < b) {
return a;
} else {
return b;
}
}
double max(double a, double b) {
if (a > b) {
return a;
} else {
return b;
}
}
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, int ifmatched) {
sqlite3 *db;
@ -355,13 +372,15 @@ void decode(char *fname, char *map, struct pool **file_keys, char ***layernames,
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'minzoom'", -1, &stmt, NULL) == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
st->minzoom = sqlite3_column_int(stmt, 0);
int minzoom = sqlite3_column_int(stmt, 0);
st->minzoom = min(st->minzoom, minzoom);
}
sqlite3_finalize(stmt);
}
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'maxzoom'", -1, &stmt, NULL) == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
st->maxzoom = sqlite3_column_int(stmt, 0);
int maxzoom = sqlite3_column_int(stmt, 0);
st->maxzoom = max(st->maxzoom, maxzoom);
}
sqlite3_finalize(stmt);
}
@ -375,7 +394,12 @@ void decode(char *fname, char *map, struct pool **file_keys, char ***layernames,
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'bounds'", -1, &stmt, NULL) == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
const unsigned char *s = sqlite3_column_text(stmt, 0);
sscanf((char *) s, "%lf,%lf,%lf,%lf", &st->minlon, &st->minlat, &st->maxlon, &st->maxlat);
double minlon, minlat, maxlon, maxlat;
sscanf((char *) s, "%lf,%lf,%lf,%lf", &minlon, &minlat, &maxlon, &maxlat);
st->minlon = min(minlon, st->minlon);
st->maxlon = max(maxlon, st->maxlon);
st->minlat = min(minlat, st->minlat);
st->maxlat = max(maxlat, st->maxlat);
}
sqlite3_finalize(stmt);
}
@ -387,7 +411,7 @@ void decode(char *fname, char *map, struct pool **file_keys, char ***layernames,
}
void usage(char **argv) {
fprintf(stderr, "Usage: %s [-f] [-i] [-c joins.csv] [-x exclude ...] -o new.mbtiles source.mbtiles\n", argv[0]);
fprintf(stderr, "Usage: %s [-f] [-i] [-c joins.csv] [-x exclude ...] -o new.mbtiles source.mbtiles ...\n", argv[0]);
exit(EXIT_FAILURE);
}
@ -515,7 +539,7 @@ int main(int argc, char **argv) {
}
}
if (argc - optind != 1 || outfile == NULL) {
if (argc - optind < 1 || outfile == NULL) {
usage(argv);
}
@ -526,6 +550,8 @@ int main(int argc, char **argv) {
sqlite3 *outdb = mbtiles_open(outfile, argv);
struct stats st;
memset(&st, 0, sizeof(st));
st.minzoom = st.minlat = st.minlon = INT_MAX;
st.maxzoom = st.maxlat = st.maxlon = INT_MIN;
struct pool *file_keys = NULL;
char **layernames = NULL;