Ignore leading zeroes when converting string attributes to feature IDs

This commit is contained in:
Eric Fischer
2018-11-07 15:46:44 -08:00
parent 949468e6f5
commit f9c9ff3853
8 changed files with 34 additions and 10 deletions
+12 -1
View File
@@ -373,6 +373,17 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox
return geom.size();
}
static std::string strip_zeroes(std::string s) {
// Doesn't do anything special with '-' followed by leading zeros
// since integer IDs must be positive
while (s.size() > 0 && s[0] == '0') {
s.erase(s.begin());
}
return s;
}
// called from frontends
int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
struct reader *r = &(*sst->readers)[sst->segment];
@@ -595,7 +606,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
fprintf(stderr, "Warning: Can't represent non-integer feature ID %s\n", sf.full_values[i].s.c_str());
warned_frac = true;
}
} else if (std::to_string(id_value) != sf.full_values[i].s) {
} else if (std::to_string(id_value) != strip_zeroes(sf.full_values[i].s)) {
static bool warned = false;
if (!warned) {