mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-04-19 16:20:54 +00:00
iOS adaptation
This commit is contained in:
parent
19dcd268c2
commit
ddbeebb563
31
main.cpp
31
main.cpp
@ -153,7 +153,7 @@ long long atoll_require(const char *s, const char *what) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void init_cpus() {
|
||||
void init_cpus(const char *tmpdir, long long max_files) {
|
||||
const char *TIPPECANOE_MAX_THREADS = getenv("TIPPECANOE_MAX_THREADS");
|
||||
|
||||
if (TIPPECANOE_MAX_THREADS != NULL) {
|
||||
@ -184,8 +184,8 @@ void init_cpus() {
|
||||
|
||||
// Don't really want too many temporary files, because the file system
|
||||
// will start to bog down eventually
|
||||
if (MAX_FILES > 2000) {
|
||||
MAX_FILES = 2000;
|
||||
if (MAX_FILES > max_files) {
|
||||
MAX_FILES = max_files;
|
||||
}
|
||||
|
||||
// MacOS can run out of system file descriptors
|
||||
@ -194,7 +194,7 @@ void init_cpus() {
|
||||
long long fds[MAX_FILES];
|
||||
long long i;
|
||||
for (i = 0; i < MAX_FILES; i++) {
|
||||
fds[i] = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
fds[i] = open(tmpdir, O_RDONLY | O_CLOEXEC);
|
||||
if (fds[i] < 0) {
|
||||
break;
|
||||
}
|
||||
@ -2446,15 +2446,19 @@ void parse_json_source(const char *arg, struct source &src) {
|
||||
}
|
||||
|
||||
#ifdef TARGET_OS_IPHONE
|
||||
// TODO: Add func's
|
||||
int tippecanoe_main(int argc, char **argv, const char *tmp, double *persent) {
|
||||
#else
|
||||
int main(int argc, char **argv) {
|
||||
const char *tmp = "/dev/null";
|
||||
double *persent = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef MTRACE
|
||||
mtrace();
|
||||
#endif
|
||||
|
||||
av = argv;
|
||||
init_cpus();
|
||||
init_cpus(tmp, 2000);
|
||||
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
@ -2475,7 +2479,13 @@ int main(int argc, char **argv) {
|
||||
double droprate = 2.5;
|
||||
double gamma = 0;
|
||||
int buffer = 5;
|
||||
|
||||
#ifdef TARGET_OS_IPHONE
|
||||
const char *tmpdir = tmp;
|
||||
#else
|
||||
const char *tmpdir = "/tmp";
|
||||
#endif
|
||||
|
||||
const char *attribution = NULL;
|
||||
std::vector<source> sources;
|
||||
const char *prefilter = NULL;
|
||||
@ -3071,9 +3081,9 @@ int main(int argc, char **argv) {
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
files_open_at_start = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
files_open_at_start = open(tmp, O_RDONLY | O_CLOEXEC);
|
||||
if (files_open_at_start < 0) {
|
||||
perror("open /dev/null");
|
||||
perror("open tmp");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (close(files_open_at_start) != 0) {
|
||||
@ -3153,7 +3163,7 @@ int main(int argc, char **argv) {
|
||||
unlink(out_mbtiles);
|
||||
}
|
||||
|
||||
outdb = mbtiles_open(out_mbtiles, argv, forcetable);
|
||||
outdb = mbtiles_open(out_mbtiles, "tippecanoe", forcetable);
|
||||
}
|
||||
if (out_dir != NULL) {
|
||||
check_dir(out_dir, argv, force, forcetable);
|
||||
@ -3193,7 +3203,7 @@ int main(int argc, char **argv) {
|
||||
muntrace();
|
||||
#endif
|
||||
|
||||
i = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
i = open(tmp, O_RDONLY | O_CLOEXEC);
|
||||
// i < files_open_at_start is not an error, because reading from a pipe closes stdin
|
||||
if (i > files_open_at_start) {
|
||||
fprintf(stderr, "Internal error: did not close all files: %d\n", i);
|
||||
@ -3206,7 +3216,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int mkstemp_cloexec(char *name) {
|
||||
int fd = mkstemp(name);
|
||||
|
6
main.hpp
6
main.hpp
@ -14,8 +14,7 @@ struct index {
|
||||
unsigned long long seq : (64 - 18); // pack with segment and t to stay in 32 bytes
|
||||
|
||||
index()
|
||||
: t(0),
|
||||
seq(0) {
|
||||
: t(0), seq(0) {
|
||||
}
|
||||
};
|
||||
|
||||
@ -33,6 +32,9 @@ struct clipbbox {
|
||||
|
||||
extern std::vector<clipbbox> clipbboxes;
|
||||
|
||||
#ifdef TARGET_OS_IPHONE
|
||||
int tippecanoe_main(int argc, char **argv, const char *tmp, double *persent);
|
||||
#endif
|
||||
void checkdisk(std::vector<struct reader> *r);
|
||||
|
||||
extern int geometry_scale;
|
||||
|
20
mbtiles.cpp
20
mbtiles.cpp
@ -23,48 +23,48 @@ size_t max_tilestats_attributes = 1000;
|
||||
size_t max_tilestats_sample_values = 1000;
|
||||
size_t max_tilestats_values = 100;
|
||||
|
||||
sqlite3 *mbtiles_open(char *dbname, char **argv, int forcetable) {
|
||||
sqlite3 *mbtiles_open(char *dbname, const char *runner, int forcetable) {
|
||||
sqlite3 *outdb;
|
||||
|
||||
if (sqlite3_open(dbname, &outdb) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: %s: %s\n", argv[0], dbname, sqlite3_errmsg(outdb));
|
||||
fprintf(stderr, "%s: %s: %s\n", runner, dbname, sqlite3_errmsg(outdb));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char *err = NULL;
|
||||
if (sqlite3_exec(outdb, "PRAGMA synchronous=0", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: async: %s\n", argv[0], err);
|
||||
fprintf(stderr, "%s: async: %s\n", runner, err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sqlite3_exec(outdb, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: async: %s\n", argv[0], err);
|
||||
fprintf(stderr, "%s: async: %s\n", runner, err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sqlite3_exec(outdb, "PRAGMA journal_mode=DELETE", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: async: %s\n", argv[0], err);
|
||||
fprintf(stderr, "%s: async: %s\n", runner, err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sqlite3_exec(outdb, "CREATE TABLE metadata (name text, value text);", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: Tileset \"%s\" already exists. You can use --force if you want to delete the old tileset.\n", argv[0], dbname);
|
||||
fprintf(stderr, "%s: %s\n", argv[0], err);
|
||||
fprintf(stderr, "%s: Tileset \"%s\" already exists. You can use --force if you want to delete the old tileset.\n", runner, dbname);
|
||||
fprintf(stderr, "%s: %s\n", runner, err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
if (sqlite3_exec(outdb, "CREATE TABLE tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob);", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: create tiles table: %s\n", argv[0], err);
|
||||
fprintf(stderr, "%s: create tiles table: %s\n", runner, err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
if (sqlite3_exec(outdb, "create unique index name on metadata (name);", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: index metadata: %s\n", argv[0], err);
|
||||
fprintf(stderr, "%s: index metadata: %s\n", runner, err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
if (sqlite3_exec(outdb, "create unique index tile_index on tiles (zoom_level, tile_column, tile_row);", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: index tiles: %s\n", argv[0], err);
|
||||
fprintf(stderr, "%s: index tiles: %s\n", runner, err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ struct layermap_entry {
|
||||
}
|
||||
};
|
||||
|
||||
sqlite3 *mbtiles_open(char *dbname, char **argv, int forcetable);
|
||||
sqlite3 *mbtiles_open(char *dbname, const char *runner, int forcetable);
|
||||
|
||||
void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data, int size);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user