mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Merge pull request #125 from mapbox/integers
Encode numeric attributes as integers instead of floating point if possible
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 1.4.3
|
||||||
|
|
||||||
|
* Encode numeric attributes as integers instead of floating point if possible
|
||||||
|
|
||||||
## 1.4.2
|
## 1.4.2
|
||||||
|
|
||||||
* Bug fix for problem that would occasionally produce empty point geometries
|
* Bug fix for problem that would occasionally produce empty point geometries
|
||||||
|
|||||||
@@ -152,10 +152,20 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
printf(": %lld", (long long) val.int_value());
|
printf(": %lld", (long long) val.int_value());
|
||||||
} else if (val.has_double_value()) {
|
} else if (val.has_double_value()) {
|
||||||
printq(key);
|
printq(key);
|
||||||
printf(": %g", val.double_value());
|
double v = val.double_value();
|
||||||
|
if (v == (long long) v) {
|
||||||
|
printf(": %lld", (long long) v);
|
||||||
|
} else {
|
||||||
|
printf(": %g", v);
|
||||||
|
}
|
||||||
} else if (val.has_float_value()) {
|
} else if (val.has_float_value()) {
|
||||||
printq(key);
|
printq(key);
|
||||||
printf(": %g", val.float_value());
|
double v = val.float_value();
|
||||||
|
if (v == (long long) v) {
|
||||||
|
printf(": %lld", (long long) v);
|
||||||
|
} else {
|
||||||
|
printf(": %g", v);
|
||||||
|
}
|
||||||
} else if (val.has_sint_value()) {
|
} else if (val.has_sint_value()) {
|
||||||
printq(key);
|
printq(key);
|
||||||
printf(": %lld", (long long) val.sint_value());
|
printf(": %lld", (long long) val.sint_value());
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
@@ -241,6 +242,37 @@ void decode_meta(char **meta, char *stringpool, struct pool *keys, struct pool *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_integer(const char *s, long long *v) {
|
||||||
|
errno = 0;
|
||||||
|
char *endptr;
|
||||||
|
|
||||||
|
*v = strtoll(s, &endptr, 0);
|
||||||
|
if (*v == 0 && errno != 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ((*v == LLONG_MIN || *v == LLONG_MAX) && (errno == ERANGE)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (*endptr != '\0') {
|
||||||
|
// Special case: If it is an integer followed by .0000 or similar,
|
||||||
|
// it is still an integer
|
||||||
|
|
||||||
|
if (*endptr != '.') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
endptr++;
|
||||||
|
for (; *endptr != '\0'; endptr++) {
|
||||||
|
if (*endptr != '0') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
mapnik::vector::tile create_tile(char **layernames, int line_detail, std::vector<std::vector<coalesce> > &features, long long *count, struct pool **keys, struct pool **values, int nlayers) {
|
mapnik::vector::tile create_tile(char **layernames, int line_detail, std::vector<std::vector<coalesce> > &features, long long *count, struct pool **keys, struct pool **values, int nlayers) {
|
||||||
mapnik::vector::tile tile;
|
mapnik::vector::tile tile;
|
||||||
|
|
||||||
@@ -291,7 +323,16 @@ mapnik::vector::tile create_tile(char **layernames, int line_detail, std::vector
|
|||||||
mapnik::vector::tile_value *tv = layer->add_values();
|
mapnik::vector::tile_value *tv = layer->add_values();
|
||||||
|
|
||||||
if (pv->type == VT_NUMBER) {
|
if (pv->type == VT_NUMBER) {
|
||||||
|
long long v;
|
||||||
|
if (is_integer(pv->s, &v)) {
|
||||||
|
if (v >= 0) {
|
||||||
|
tv->set_int_value(v);
|
||||||
|
} else {
|
||||||
|
tv->set_sint_value(v);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
tv->set_double_value(atof(pv->s));
|
tv->set_double_value(atof(pv->s));
|
||||||
|
}
|
||||||
} else if (pv->type == VT_BOOLEAN) {
|
} else if (pv->type == VT_BOOLEAN) {
|
||||||
tv->set_bool_value(pv->s[0] == 't');
|
tv->set_bool_value(pv->s[0] == 't');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user