mapbox / geojsonhint

IMPORTANT: This repo will be archived. Use @placemarkio/check-geojson instead
ISC License
258 stars 37 forks source link

Turn off precision warning by default #49

Closed tmcw closed 8 years ago

tmcw commented 8 years ago

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.

mourner commented 8 years ago

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);