Large integer attribute values are altered
Closed this issue · 2 comments
For example, using the Census TIGER states dataset, the attributes ALAND and AWATER are large integers (e.g. 62266581604
).
Here they are getting encoded as float
types and thus get altered (e.g., 62266580992
).
For testing I was doing this: shp -> geobuf -> geojson and comparing the property values.
I tried adding the ability to detect and set integer types around line 149 but that produced odd property values in geojson (e.g., "ALAND":{"low":2137039460,"high":14,"unsigned":true}
). Presumably this is because Long is not used (but should be)?
Simply setting the values as double
type preserves proper values, but produces a bigger geobuf file (as expected).
Presumably the proper fix would be to detect the proper numeric type and encode using that, e.g.,
switch (typeof v) {
case 'number':
if (v|0 === v){
val.set((v > 0)? 'uint_value': 'int_value', v);
}
else {
val.set('float_value', v);
}
break;
case 'boolean':
val.set('bool_value', v);
break;
case 'string':
val.set('string_value', v.toString());
Not sure how to detect which to use: float
vs double
but in this case we wanted uint
anyway.