mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-22 12:28:03 +00:00
Merge pull request #148 from mapbox/option-check
Give an error if -p or -a is used with an undefined option letter
This commit is contained in:
commit
20bd661693
26
geojson.c
26
geojson.c
@ -1826,6 +1826,18 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
|
||||
return ret;
|
||||
}
|
||||
|
||||
int int_in(int v, int *a, int len) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (a[i] == v) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
#ifdef MTRACE
|
||||
mtrace();
|
||||
@ -1961,14 +1973,24 @@ int main(int argc, char **argv) {
|
||||
case 'p': {
|
||||
char *cp;
|
||||
for (cp = optarg; *cp != '\0'; cp++) {
|
||||
prevent[*cp & 0xFF] = 1;
|
||||
if (int_in(*cp, prevent_options, sizeof(prevent_options) / sizeof(prevent_options[0]))) {
|
||||
prevent[*cp & 0xFF] = 1;
|
||||
} else {
|
||||
fprintf(stderr, "%s: Unknown option -p%c\n", argv[0], *cp);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case 'a': {
|
||||
char *cp;
|
||||
for (cp = optarg; *cp != '\0'; cp++) {
|
||||
additional[*cp & 0xFF] = 1;
|
||||
if (int_in(*cp, additional_options, sizeof(additional_options) / sizeof(additional_options[0]))) {
|
||||
additional[*cp & 0xFF] = 1;
|
||||
} else {
|
||||
fprintf(stderr, "%s: Unknown option -a%c\n", argv[0], *cp);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
|
18
tile.cc
18
tile.cc
@ -502,7 +502,7 @@ void *partial_feature_worker(void *v) {
|
||||
char *additional = (*partials)[i].additional;
|
||||
int maxzoom = (*partials)[i].maxzoom;
|
||||
|
||||
if ((t == VT_LINE || t == VT_POLYGON) && !(prevent['s' & 0xFF] || (z == maxzoom && prevent['S' & 0xFF]))) {
|
||||
if ((t == VT_LINE || t == VT_POLYGON) && !(prevent[P_SIMPLIFY] || (z == maxzoom && prevent[P_SIMPLIFY_LOW]))) {
|
||||
if (1 /* !reduced */) { // XXX why did this not simplify if reduced?
|
||||
if (t == VT_LINE) {
|
||||
geom = remove_noop(geom, t, 32 - z - line_detail);
|
||||
@ -518,7 +518,7 @@ void *partial_feature_worker(void *v) {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (t == VT_LINE && additional['r' & 0xFF]) {
|
||||
if (t == VT_LINE && additional[A_REVERSE]) {
|
||||
geom = reorder_lines(geom);
|
||||
}
|
||||
|
||||
@ -746,7 +746,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gamma >= 0 && (t == VT_POINT || (additional['l' & 0xFF] && t == VT_LINE))) {
|
||||
if (gamma >= 0 && (t == VT_POINT || (additional[A_LINE_DROP] && t == VT_LINE))) {
|
||||
seq++;
|
||||
if (seq >= 0) {
|
||||
seq -= interval;
|
||||
@ -880,7 +880,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
||||
}
|
||||
|
||||
for (j = 0; j < nlayers; j++) {
|
||||
if (additional['o' & 0xFF]) {
|
||||
if (additional[A_REORDER]) {
|
||||
std::sort(features[j].begin(), features[j].end());
|
||||
}
|
||||
|
||||
@ -895,7 +895,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
||||
}
|
||||
#endif
|
||||
|
||||
if (additional['c' & 0xFF] && out.size() > 0 && out[y].geom.size() + features[j][x].geom.size() < 20000 && coalcmp(&features[j][x], &out[y]) == 0 && features[j][x].type != VT_POINT) {
|
||||
if (additional[A_COALESCE] && out.size() > 0 && out[y].geom.size() + features[j][x].geom.size() < 20000 && coalcmp(&features[j][x], &out[y]) == 0 && features[j][x].type != VT_POINT) {
|
||||
unsigned z;
|
||||
for (z = 0; z < features[j][x].geom.size(); z++) {
|
||||
out[y].geom.push_back(features[j][x].geom[z]);
|
||||
@ -920,7 +920,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
||||
}
|
||||
features[j] = out;
|
||||
|
||||
if (prevent['i' & 0xFF]) {
|
||||
if (prevent[P_INPUT_ORDER]) {
|
||||
std::sort(features[j].begin(), features[j].end(), preservecmp);
|
||||
}
|
||||
}
|
||||
@ -936,7 +936,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
||||
}
|
||||
|
||||
if (totalsize > 0) {
|
||||
if (totalsize > 200000 && !prevent['f' & 0xFF]) {
|
||||
if (totalsize > 200000 && !prevent[P_FEATURE_LIMIT]) {
|
||||
fprintf(stderr, "tile %d/%u/%u has %lld features, >200000 \n", z, tx, ty, totalsize);
|
||||
fprintf(stderr, "Try using -z to set a higher base zoom level.\n");
|
||||
return -1;
|
||||
@ -956,12 +956,12 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
||||
tile.SerializeToString(&s);
|
||||
compress(s, compressed);
|
||||
|
||||
if (compressed.size() > 500000 && !prevent['k' & 0xFF]) {
|
||||
if (compressed.size() > 500000 && !prevent[P_KILOBYTE_LIMIT]) {
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "tile %d/%u/%u size is %lld with detail %d, >500000 \n", z, tx, ty, (long long) compressed.size(), line_detail);
|
||||
}
|
||||
|
||||
if (prevent['d' & 0xFF]) {
|
||||
if (prevent[P_DYNAMIC_DROP]) {
|
||||
// The 95% is a guess to avoid too many retries
|
||||
// and probably actually varies based on how much duplicated metadata there is
|
||||
|
||||
|
26
tile.h
26
tile.h
@ -35,3 +35,29 @@ extern int quiet;
|
||||
|
||||
extern int CPUS;
|
||||
extern int TEMP_FILES;
|
||||
|
||||
static int additional_options[] = {
|
||||
#define A_COALESCE ((int) 'c')
|
||||
A_COALESCE,
|
||||
#define A_REVERSE ((int) 'r')
|
||||
A_REVERSE,
|
||||
#define A_REORDER ((int) 'o')
|
||||
A_REORDER,
|
||||
#define A_LINE_DROP ((int) 'l')
|
||||
A_LINE_DROP,
|
||||
};
|
||||
|
||||
static int prevent_options[] = {
|
||||
#define P_SIMPLIFY ((int) 's')
|
||||
P_SIMPLIFY,
|
||||
#define P_SIMPLIFY_LOW ((int) 'S')
|
||||
P_SIMPLIFY_LOW,
|
||||
#define P_FEATURE_LIMIT ((int) 'f')
|
||||
P_FEATURE_LIMIT,
|
||||
#define P_KILOBYTE_LIMIT ((int) 'k')
|
||||
P_KILOBYTE_LIMIT,
|
||||
#define P_DYNAMIC_DROP ((int) 'd')
|
||||
P_DYNAMIC_DROP,
|
||||
#define P_INPUT_ORDER ((int) 'i')
|
||||
P_INPUT_ORDER,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user