mapbox/geojsonhint

Turn off precision warning by default

Closed this issue · 1 comments

tmcw commented

I don't think that this warning makes sense for geojsonhint by default. Even if it's a warning, there are way too many cases where it's irrelevant: when GeoJSON objects are in memory, or have been processed by some algorithm, there's no point to reducing decimal accuracy since the coordinates will be stored as floating point values regardless of used precision. In the Studio case, this was surprising and we had to turn it off, and given the scarcity of tools that do truncate precision, I just don't think it's typically useful or accurate.

given the scarcity of tools that do truncate precision

Here's a short function that should do the job in theory, in case anyone is looking:

function cutPrecision(obj, e) {
    if (typeof obj[0] === 'number') {
        for (var i = 0; i < obj.length; i++) obj[i] = Math.round(obj[i] * e) / e;
    } else {
        var arr = obj.features || obj.geometries || obj.coordinates || obj;
        for (var i = 0; i < arr.length; i++) cutPrecision(arr[i], e);
    }    
}

cutPrecision(geosjon, 1e6);