turf.truncate
What is turf.truncate?
turf.truncate walks every coordinate in a GeoJSON Feature, FeatureCollection, or Geometry and trims it to a given decimal precision. Optionally it also strips the Z value.
turf.truncate(geojson, options?) → Feature<Geometry>Options include:
precision— number of decimal places (default6)coordinates— maximum coordinates per position, e.g.2to strip Z (default3)mutate—boolean(defaultfalse); whentrue, mutates the input in place
When would you use turf.truncate?
Use turf.truncate to shrink GeoJSON payloads before sending to a client or saving to storage. Six decimal places of longitude/latitude ≈ 11 cm on the ground, which is more than enough for almost every map interaction — trimming to six is a lossless change for UI purposes but can cut file size substantially for dense geometries.
In Node.js ETL, turf.truncate is a common step before emitting static GeoJSON assets served by Gatsby, Netlify, or Vercel. It also keeps Git diffs stable when you check GeoJSON fixtures into a repo and want cosmetic edits to remain small.
undefinedFAQs
How much precision do I need?
6 decimal places ≈ 11 cm — safe for almost all mapping work. 5 ≈ 1.1 m (fine for address-level work). 4 ≈ 11 m (good for city-block scale). 3 ≈ 110 m (noticeable drift in urban mapping). Start with 6 and reduce only when payload size is critical.
Does it change the shape?
Rounding coordinates shifts them slightly. At precision 6 the shift is sub-decimetre and imperceptible. At lower precision the changes become visible, especially for dense polygons.
How do I install just truncate?
npm install @turf/truncate. It depends on @turf/meta and @turf/helpers.
Can I strip Z values?
Yes — set coordinates: 2 to keep only [lng, lat] in every position and drop any altitude or M value.