Allow passing a file with a list of input files to tile-join in response to issue 69 (#73)

* Allow passing a file with a list of input files to tile-join in response to Issue 69 (https://github.com/felt/tippecanoe/issues/69)

* Do not print usage if -r is specified without a commandline readfrom file

* Add test for -r option to tile-join
This commit is contained in:
DarcyB
2023-02-24 11:31:46 -08:00
committed by GitHub
parent f2127fec97
commit 0fa758c1e3
4 changed files with 52 additions and 13 deletions
+40 -13
View File
@@ -411,7 +411,6 @@ struct reader {
struct reader *begin_reading(char *fname) {
struct reader *r = new reader;
r->name = fname;
struct stat st;
if (stat(fname, &st) == 0 && (st.st_mode & S_IFDIR) != 0) {
r->db = NULL;
@@ -959,7 +958,7 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
}
void usage(char **argv) {
fprintf(stderr, "Usage: %s [-f] [-i] [-pk] [-pC] [-c joins.csv] [-X] [-x exclude ...] -o new.mbtiles source.mbtiles ...\n", argv[0]);
fprintf(stderr, "Usage: %s [-f] [-i] [-pk] [-pC] [-c joins.csv] [-X] [-x exclude ...] [-r inputfile.txt ] -o new.mbtiles source.mbtiles ...\n", argv[0]);
exit(EXIT_ARGS);
}
@@ -970,8 +969,11 @@ int main(int argc, char **argv) {
char *csv = NULL;
int force = 0;
int ifmatched = 0;
int filearg = 0;
json_object *filter = NULL;
struct reader *readers = NULL;
CPUS = sysconf(_SC_NPROCESSORS_ONLN);
const char *TIPPECANOE_MAX_THREADS = getenv("TIPPECANOE_MAX_THREADS");
@@ -1011,6 +1013,7 @@ int main(int argc, char **argv) {
{"feature-filter-file", required_argument, 0, 'J'},
{"feature-filter", required_argument, 0, 'j'},
{"rename-layer", required_argument, 0, 'R'},
{"read-from", required_argument, 0, 'r'},
{"no-tile-size-limit", no_argument, &pk, 1},
{"no-tile-compression", no_argument, &pC, 1},
@@ -1143,6 +1146,29 @@ int main(int argc, char **argv) {
break;
}
case 'r': {
std::fstream read_file;
read_file.open(std::string(optarg), std::ios::in);
if (read_file.is_open()) {
std::string sa;
filearg = 1;
while (getline(read_file, sa)) {
char* c = const_cast<char*>(sa.c_str());
reader *r = begin_reading(c);
struct reader **rr;
for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) {
if (*r < **rr) {
break;
}
}
r->next = *rr;
*rr = r;
}
read_file.close();
}
}
case 'q':
quiet = true;
break;
@@ -1167,7 +1193,7 @@ int main(int argc, char **argv) {
}
}
if (argc - optind < 1) {
if ((argc - optind < 1) && (filearg == 0)) {
usage(argv);
}
@@ -1211,20 +1237,21 @@ int main(int argc, char **argv) {
std::string description;
std::string name;
struct reader *readers = NULL;
for (i = optind; i < argc; i++) {
reader *r = begin_reading(argv[i]);
struct reader **rr;
if (filearg == 0) {
for (i = optind; i < argc; i++) {
reader *r = begin_reading(argv[i]);
struct reader **rr;
for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) {
if (*r < **rr) {
break;
for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) {
if (*r < **rr) {
break;
}
}
}
r->next = *rr;
*rr = r;
r->next = *rr;
*rr = r;
}
}
std::map<std::string, std::string> attribute_descriptions;