turf.flip
What is turf.flip?
turf.flip swaps the first two elements of every coordinate in any GeoJSON Feature, FeatureCollection, or Geometry. It is the easiest way to recover from [lat, lng] input when the GeoJSON spec (and Turf) expects [lng, lat].
turf.flip(geojson, options?) → Feature<Geometry>Options include:
mutate—boolean(defaultfalse); whentrue, mutates the input in place
When would you use turf.flip?
Use turf.flip when consuming data from sources that emit [lat, lng] order — commonly Leaflet exports, some legacy APIs, or spreadsheet pipelines where a developer mixed up the axes. Run turf.flip on the input and then you can feed it to the rest of Turf without worrying about downstream errors.
It is also handy during client-side form processing: for example, converting user-entered latitude/longitude in a natural order into GeoJSON coordinates before saving, or converting between backend and frontend conventions in a Node.js service.
undefinedFAQs
Does it touch the Z coordinate if present?
No. turf.flip swaps only the first two positions in each coordinate, preserving elevation or any additional values.
How do I install just flip?
npm install @turf/flip. It depends on @turf/meta and @turf/helpers.
What is GeoJSON's expected order?
The GeoJSON spec (RFC 7946) requires [longitude, latitude] (i.e. [x, y]). Turf, Mapbox, and MapLibre all assume this. Anywhere you see [lat, lng] (Google, Leaflet examples) you need to flip before handing the data to Turf.
Can I use this on FeatureCollections?
Yes. turf.flip recursively visits every coordinate via @turf/meta regardless of container type, so it handles any valid GeoJSON input.