-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (35 loc) · 956 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var coordEach = require('turf-meta').coordEach;
/**
* Takes input features and flips all of their coordinates
* from `[x, y]` to `[y, x]`.
*
* @module turf/flip
* @category misc
* @param {(Feature|FeatureCollection)} input input features
* @returns {(Feature|FeatureCollection)} a feature or set of features of the same type as `input` with flipped coordinates
* @example
* var serbia = {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [20.566406, 43.421008]
* }
* };
*
* //=serbia
*
* var saudiArabia = turf.flip(serbia);
*
* //=saudiArabia
*/
module.exports = function (_) {
// ensure that we don't modify features in-place and changes to the
// output do not change the previous feature, including changes to nested
// properties.
var input = JSON.parse(JSON.stringify(_));
coordEach(input, function (coord) {
coord.reverse();
});
return input;
};